diff options
6 files changed, 44 insertions, 43 deletions
diff --git a/src/plugins/xml/XmlOutput.cpp b/src/plugins/xml/XmlOutput.cpp index 0d7b0dc..1a7ea2a 100644 --- a/src/plugins/xml/XmlOutput.cpp +++ b/src/plugins/xml/XmlOutput.cpp @@ -276,14 +276,17 @@ static Rooted<Element> transformFieldDescriptor(Handle<Element> parent, std::map<std::string, std::string> attrs; addNameAttribute(fd, attrs); bool isSubtree = fd->getFieldType() == FieldDescriptor::FieldType::SUBTREE; - attrs.emplace("subtree", getStringForBool(isSubtree)); - attrs.emplace("optional", getStringForBool(fd->isOptional())); + if (isSubtree) { + attrs.emplace("subtree", getStringForBool(true)); + } + if (fd->isOptional()) { + attrs.emplace("optional", getStringForBool(true)); + } // TODO: whitespace mode? // create the XML element itself. Rooted<Element> fieldDescriptor{new Element(P.mgr, parent, tagName, attrs)}; // translate the syntax. Rooted<Element> syntax{new Element(P.mgr, parent, "syntax")}; - fieldDescriptor->addChild(syntax); { Rooted<Element> open = transformTokenDescriptor(syntax, fd->getOpenToken(), "open", P); @@ -296,6 +299,9 @@ static Rooted<Element> transformFieldDescriptor(Handle<Element> parent, syntax->addChild(close); } } + if (!syntax->getChildren().empty()) { + fieldDescriptor->addChild(syntax); + } if (!fd->isPrimitive()) { // translate the child references. for (auto s : fd->getChildren()) { @@ -323,7 +329,9 @@ static void transformDescriptor(Handle<Element> elem, Handle<Element> syntax, elem, "attributes", "attribute", d->getAttributesDescriptor(), P); // remove the parent entry if it is there. attributes->getAttributes().erase("parent"); - elem->addChild(attributes); + if (!attributes->getChildren().empty()) { + elem->addChild(attributes); + } // transform the syntactic sugar description. { Rooted<Element> open = @@ -350,20 +358,25 @@ static Rooted<Element> transformStructuredClass(Handle<Element> parent, { Rooted<Element> structuredClass{new Element(P.mgr, parent, "struct")}; // transform the specific StructuredClass properties. - structuredClass->getAttributes().emplace( - "cardinality", toString(Variant(s->getCardinality()), P)); + if (s->getCardinality() != Cardinality::any()) { + structuredClass->getAttributes().emplace( + "cardinality", toString(Variant(s->getCardinality()), P)); + } if (s->getSuperclass() != nullptr) { structuredClass->getAttributes().emplace( "isa", getStructuredClassRef(s, s->getSuperclass())); } - structuredClass->getAttributes().emplace( - "transparent", getStringForBool(s->isTransparent())); - structuredClass->getAttributes().emplace( - "root", getStringForBool(s->hasRootPermission())); + if (s->isTransparent()) { + structuredClass->getAttributes().emplace("transparent", + getStringForBool(true)); + } + if (s->hasRootPermission()) { + structuredClass->getAttributes().emplace("root", + getStringForBool(true)); + } // transform the syntactic sugar descriptors Rooted<Element> syntax{new Element(P.mgr, structuredClass, "syntax")}; - structuredClass->addChild(syntax); { Rooted<Element> shortForm = transformTokenDescriptor(syntax, s->getShortToken(), "short", P); @@ -374,6 +387,9 @@ static Rooted<Element> transformStructuredClass(Handle<Element> parent, // transform the descriptor properties transformDescriptor(structuredClass, syntax, s, P); + if (!syntax->getChildren().empty()) { + structuredClass->addChild(syntax); + } return structuredClass; } @@ -383,8 +399,10 @@ static Rooted<Element> transformAnnotationClass(Handle<Element> parent, { Rooted<Element> annotationClass{new Element(P.mgr, parent, "struct")}; Rooted<Element> syntax{new Element(P.mgr, annotationClass, "syntax")}; - annotationClass->addChild(syntax); transformDescriptor(annotationClass, syntax, a, P); + if (!syntax->getChildren().empty()) { + annotationClass->addChild(syntax); + } return annotationClass; } diff --git a/testdata/integration/basic_functionality/lots_of_empty_elements.out.osxml b/testdata/integration/basic_functionality/lots_of_empty_elements.out.osxml index 07caa33..21935f2 100644 --- a/testdata/integration/basic_functionality/lots_of_empty_elements.out.osxml +++ b/testdata/integration/basic_functionality/lots_of_empty_elements.out.osxml @@ -1,11 +1,8 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <document> <ontology name="test"> - <struct cardinality="{*}" name="a" root="true" transparent="false"> - <syntax/> - <attributes/> - <field name="afield" optional="false" subtree="true"> - <syntax/> + <struct name="a" root="true"> + <field name="afield" subtree="true"> <childRef ref="a"/> </field> </struct> diff --git a/testdata/integration/ontology_serialization/attributes_descriptor.out.osxml b/testdata/integration/ontology_serialization/attributes_descriptor.out.osxml index 00f21f5..44b7aef 100644 --- a/testdata/integration/ontology_serialization/attributes_descriptor.out.osxml +++ b/testdata/integration/ontology_serialization/attributes_descriptor.out.osxml @@ -1,14 +1,12 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <document> <ontology name="test"> - <struct cardinality="{*}" name="a" root="true" transparent="false"> - <syntax/> + <struct name="a" root="true"> <attributes> <attribute default="4" name="myAttr" type="int"/> </attributes> </struct> - <struct cardinality="{*}" isa="a" name="b" root="false" transparent="false"> - <syntax/> + <struct isa="a" name="b"> <attributes> <attribute default="bla" name="myOtherAttr" type="string"/> </attributes> diff --git a/testdata/integration/ontology_serialization/simple.out.osxml b/testdata/integration/ontology_serialization/simple.out.osxml index 4aa15a6..2d00fc5 100644 --- a/testdata/integration/ontology_serialization/simple.out.osxml +++ b/testdata/integration/ontology_serialization/simple.out.osxml @@ -1,22 +1,15 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <document> <ontology name="test"> - <struct cardinality="{*}" name="a" root="true" transparent="false"> - <syntax/> - <attributes/> - <field name="afield" optional="false" subtree="true"> - <syntax/> + <struct name="a" root="true"> + <field name="afield" subtree="true"> <childRef ref="a"/> </field> - <field optional="true" subtree="false"> - <syntax/> + <field optional="true"> <childRef ref="b"/> </field> </struct> - <struct cardinality="{1, 7-8}" name="b" root="false" transparent="true"> - <syntax/> - <attributes/> - </struct> + <struct cardinality="{1, 7-8}" name="b" transparent="true"/> </ontology> <test:a> <afield/> diff --git a/testdata/integration/ontology_serialization/syntax.out.osxml b/testdata/integration/ontology_serialization/syntax.out.osxml index 3e8190a..79909fe 100644 --- a/testdata/integration/ontology_serialization/syntax.out.osxml +++ b/testdata/integration/ontology_serialization/syntax.out.osxml @@ -1,17 +1,15 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <document> <ontology name="test"> - <struct cardinality="{*}" name="a" root="true" transparent="false"> + <struct name="a" root="true"> + <field> + <childRef ref="a"/> + </field> <syntax> <short>§</short> <open><<</open> <close>>></close> </syntax> - <attributes/> - <field optional="false" subtree="false"> - <syntax/> - <childRef ref="a"/> - </field> </struct> </ontology> <test:a> diff --git a/testdata/integration/ontology_serialization/typesystem.out.osxml b/testdata/integration/ontology_serialization/typesystem.out.osxml index a822191..4811b87 100644 --- a/testdata/integration/ontology_serialization/typesystem.out.osxml +++ b/testdata/integration/ontology_serialization/typesystem.out.osxml @@ -1,14 +1,11 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <document> <ontology name="test"> - <struct cardinality="{*}" name="a" root="true" transparent="false"> - <syntax/> + <struct name="a" root="true"> <attributes> <attribute name="type" type="bla.myEnum"/> </attributes> - <primitive optional="false" subtree="false" type="bla.myStruct"> - <syntax/> - </primitive> + <primitive type="bla.myStruct"/> </struct> </ontology> <typesystem name="bla"> |