Skip to content

Commit 2e65897

Browse files
committed
[kxml_compiler]The kxml_compiler segfaulted when generated code from an
XSD where the root element was a complexType which was a sequence of elements. This was becasuse the subelements was not added by the schema/ parser class during the parse.
1 parent 101e0e7 commit 2e65897

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

kxml_compiler/creator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ ClassDescription Creator::createClassDescription(const Schema::Element &element)
260260

261261
QString targetClassName = Namer::getClassName(targetElement.name());
262262

263-
if (targetElement.text() && !targetElement.hasAttributeRelations() && !r.isList()) {
263+
if ((targetElement.text() || targetElement.type() < Schema::Element::ComplexType)
264+
&& !targetElement.hasAttributeRelations() && !r.isList()) {
264265
if (mVerbose) {
265266
qDebug() << " FLATTEN";
266267
}

kxml_compiler/kxml_compiler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ int main(int argc, char **argv)
292292
qDebug() << "Create classes";
293293
}
294294
foreach (Schema::Element e, schemaDocument.usedElements()) {
295-
if (!e.text()) {
295+
// only generate classes for the simple types (nodes with no childs/attributes)
296+
if (!e.text()
297+
&& !(e.attributeRelations().count() == 0 && e.elementRelations().count() == 0)) {
296298
c.createClass(e);
297299
}
298300
}

kxml_compiler/parsercreatordom.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ void ParserCreatorDom::createElementParser(KODE::Class &c, const Schema::Element
9696

9797
Schema::Element targetElement = creator()->document().element((*it).target());
9898

99-
if (targetElement.text() && !targetElement.hasAttributeRelations() && !(*it).isList()) {
99+
if ((targetElement.text() || targetElement.type() < Schema::Node::ComplexType)
100+
&& !targetElement.hasAttributeRelations() && !(*it).isList()) {
100101
QString data = stringToDataConverter("e.text()", targetElement.type());
101102
code += "result.set" + className + "( " + data + " );";
102103
} else {

kxml_compiler/parserxsd.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ Schema::Document ParserXsd::parse(const XSD::Parser &parser)
109109
e.setBaseType(Schema::Node::String);
110110
} else if (complexType.baseTypeName().qname() == "xs:boolean") {
111111
e.setBaseType(Schema::Node::Boolean);
112+
} else if (complexType.baseTypeName().qname() == "xs:decimal") {
113+
e.setBaseType(Schema::Node::Decimal);
114+
} else if (complexType.baseTypeName().qname() == "xs:date") {
115+
e.setBaseType(Schema::Node::Date);
112116
} else if (complexType.baseTypeName().qname() == "xs:normalizedString") {
113117
e.setBaseType(Schema::Node::NormalizedString);
114118
} else if (complexType.baseTypeName().qname() == "xs:token") {
@@ -120,6 +124,10 @@ Schema::Document ParserXsd::parse(const XSD::Parser &parser)
120124
e.setType(Schema::Node::String);
121125
} else if (element.type().qname() == "xs:boolean") {
122126
e.setType(Schema::Node::Boolean);
127+
} else if (element.type().qname() == "xs:decimal") {
128+
e.setType(Schema::Node::Decimal);
129+
} else if (element.type().qname() == "xs:date") {
130+
e.setType(Schema::Node::Date);
123131
} else if (element.type().qname() == "xs:normalizedString") {
124132
e.setType(Schema::Node::NormalizedString);
125133
} else if (element.type().qname() == "xs:token") {

kxml_compiler/schema.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ class KSCHEMA_EXPORT Node : public Annotatable
9898
Int, // xs:int -> signed 32-bit integer
9999
Date,
100100
Enumeration,
101-
ComplexType,
102101
DateTime,
103102
Decimal,
104-
Boolean
103+
Boolean,
104+
ComplexType // always keep this as a last
105105
};
106+
106107
Node();
107108
virtual ~Node();
108109

schema/parser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ void Parser::parseCompositor(ParserContext *context, const QDomElement &element,
370370
foreach (Element e, newElements) {
371371
e.setCompositor(compositor);
372372
ct.addElement(e);
373+
d->mElements.append(e);
373374
}
374375
}
375376
}
@@ -734,7 +735,7 @@ void Parser::addGlobalElement(const Element &newElement)
734735
}
735736

736737
if (!found) {
737-
d->mElements.append(newElement);
738+
d->mElements.prepend(newElement);
738739
}
739740
}
740741

0 commit comments

Comments
 (0)