-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XML elements out of order after serializing #213
Comments
Another issue is that the namespace |
If you need a real *.reqif file for testing, let me know and I'll prepare one. The one I use contains some sensitive data. |
yes please a sample xml would be great, it seems like something with the sequential flag is not generating properly maybe |
Here is an example of such a *.reqif file: Please note, that I added the ".txt" extension, as otherwise Github wouldn't have let me upload the file. |
Just for sanity reasons, you can grab the namespaces registry from the parser and pass it to the serializer.render method in order to use the same prefixes, easier to compare.
<xsd:element maxOccurs="1" minOccurs="0" name="DATATYPES">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="DATATYPE-DEFINITION-BOOLEAN" type="REQIF:DATATYPE-DEFINITION-BOOLEAN"/>
<xsd:element name="DATATYPE-DEFINITION-DATE" type="REQIF:DATATYPE-DEFINITION-DATE"/>
<xsd:element name="DATATYPE-DEFINITION-ENUMERATION" type="REQIF:DATATYPE-DEFINITION-ENUMERATION"/>
<xsd:element name="DATATYPE-DEFINITION-INTEGER" type="REQIF:DATATYPE-DEFINITION-INTEGER"/>
<xsd:element name="DATATYPE-DEFINITION-REAL" type="REQIF:DATATYPE-DEFINITION-REAL"/>
<xsd:element name="DATATYPE-DEFINITION-STRING" type="REQIF:DATATYPE-DEFINITION-STRING"/>
<xsd:element name="DATATYPE-DEFINITION-XHTML" type="REQIF:DATATYPE-DEFINITION-XHTML"/>
</xsd:choice>
</xsd:complexType>
</xsd:element> Any of the Also since these fields can appear more than once they are generated as lists elements. The serializer is going through the values of each list before moving to the next field. In a nutshell that's the normal behavior, I also run the output through xsd validation and passes without issues parser = XmlParser()
obj = parser.from_path(Path("example.reqif.txt"), ReqIf)
serializer = XmlSerializer(pretty_print=True, encoding="ascii")
tree = serializer.render_tree(obj, parser.namespaces)
xmlschema_doc = etree.parse("schemas/reqif.xsd")
xmlschema = etree.XMLSchema(xmlschema_doc)
xmlschema.assertValid(tree) Are you seeing any specific errors from the |
@tefra Regarding ordering, I think we talk of two different things. For the ordering of The snippets I posted in the initial issue description however refer to The serialized may still be valid, but the result when opening the document looks different. |
Oh from the sample this part right? <xhtml:b>Titel</xhtml:b> : Test Titel <xhtml:br/>
<xhtml:b>Bearbeiter</xhtml:b> : Test Bearbeiter <xhtml:br/>
<xhtml:b>Abt./OE</xhtml:b> : Test Abteilung <xhtml:br/>
<xhtml:b>Telefon</xhtml:b> : Test Telefon <xhtml:br/>
<xhtml:b>E-Mail:</xhtml:b> some.body@example.com <xhtml:br/>
<xhtml:b>Erstausgabe:</xhtml:b> 09.03.2020 <xhtml:br/>
<xhtml:b>Datum Änderungsstand</xhtml:b> : 09.03.2020 <xhtml:br/>
<xhtml:b>Änderungsstand</xhtml:b> : V1.0 in xsdata output all the br elements are rendered first.... <ns1:br xml:space="preserve"/>
<ns1:br xml:space="preserve"/>
<ns1:br xml:space="preserve"/>
<ns1:br xml:space="preserve"/>
<ns1:br xml:space="preserve"/>
<ns1:br xml:space="preserve"/>
<ns1:br xml:space="preserve"/>
<ns1:b xml:space="preserve">Titel</ns1:b>: Test Titel
<ns1:b xml:space="preserve">Bearbeiter</ns1:b>: Test Bearbeiter
<ns1:b xml:space="preserve">Abt./OE</ns1:b>: Test Abteilung
<ns1:b xml:space="preserve">Telefon</ns1:b>: Test Telefon
<ns1:b xml:space="preserve">E-Mail:</ns1:b>some.body@example.com
<ns1:b xml:space="preserve">Erstausgabe:</ns1:b>09.03.2020
<ns1:b xml:space="preserve">Datum Änderungsstand</ns1:b>: 09.03.2020
<ns1:b xml:space="preserve">Änderungsstand</ns1:b>: V1.0 |
Yes, this is the part of concern.
|
The issue was that when a class has a mixed content field and a field that matches exactly an element qualified name, the exact match always had higher priority, which shouldn't happen. I refactored a lot of the mixed content handling, you will need to re-generate your models because a new metadata key was introduced with name: The sample you provided is now rendered correctly, give it a try from master and let me know if it works as expected in other use cases as well. <THE-VALUE>
<xhtml:p xml:space="preserve"><xhtml:b xml:space="preserve">Titel</xhtml:b>
: Test Titel
<xhtml:br xml:space="preserve"/>
<xhtml:b xml:space="preserve">Bearbeiter</xhtml:b>: Test Bearbeiter
<xhtml:br xml:space="preserve"/>
<xhtml:b xml:space="preserve">Abt./OE</xhtml:b>: Test Abteilung
<xhtml:br xml:space="preserve"/>
<xhtml:b xml:space="preserve">Telefon</xhtml:b>: Test Telefon
<xhtml:br xml:space="preserve"/>
<xhtml:b xml:space="preserve">E-Mail:</xhtml:b>some.body@example.com
<xhtml:br xml:space="preserve"/>
<xhtml:b xml:space="preserve">Erstausgabe:</xhtml:b>09.03.2020
<xhtml:br xml:space="preserve"/>
<xhtml:b xml:space="preserve">Datum Änderungsstand</xhtml:b>:
09.03.2020
<xhtml:br xml:space="preserve"/>
<xhtml:b xml:space="preserve">Änderungsstand</xhtml:b>: V1.0</xhtml:p>
</THE-VALUE>
Thank you for reporting @ansFourtyTwo, this issue helped to improve mixed content handling a lot! |
Hi @tefra The file I currently work with no looks good. Thank you very much. Once again, you are doing a great job. I decided to use All the best. |
Thank you @ansFourtyTwo , This library is something I wanted to create since the original suds soap client stopped being maintained, It gives me great pleasure to see other people use it! |
After creating DataClasses for the ReqIF schema with
I tried to parse an example ReqIf file and serialize back to XML. It seems that internally elements are stored withing lists and serializing does not preserve the correct order of the elements.
This snippet is from the original document:
This is the corresponding section from the serialized document
This is the code I used for this back and forth parsing and serializing:
The text was updated successfully, but these errors were encountered: