IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

XML file created with XMLSpy generated code does not pass schema validation Options · View
econex
Posted: Thursday, May 4, 2017 9:50:07 AM
Rank: Newbie

Joined: 5/4/2017
Posts: 3
I ve tried to use XMLSpy to generate C# code out of my XSD schema. Then I ve used the code to create a new document and add there some elements. Then I passed resulting XML for validation and it failed.

My schema contains many xsd:sequence elements. When I add document elements through generated code, I do it it in arbitrary order according to program logic. Naturally, I would expect that generated code will observe XSD and re-arrange added elements on XML output. Instead, it outputs all elements in their order of addition, which makes XML invalid against XSD provided.

It looks as a critical issue, which will block us from choosing XMLSpy for our development tasks. How to resolve this problem? Thank you in advance.
island
Posted: Friday, May 5, 2017 6:03:41 AM
Rank: Newbie

Joined: 10/28/2002
Posts: 1,283
Location: AT
The generated code does not enforce content models so it would be necessary to add the elements in the order that is defined in the schema.

See bottom of following page for more details:

http://manual.altova.com/XMLSpy/spyenterprise/cg_schema.htm
econex
Posted: Sunday, May 7, 2017 1:28:15 PM
Rank: Newbie

Joined: 5/4/2017
Posts: 3
This looks as a serious limitation. By default, unless tedious precautions are taken, which are not controlled or even described by code generated by Altova, generated code emits invalid XML not passing simple basic XSD validation.

Is there at all a way to know correct sequences from code itself? Is there at least a guarantee that class fields appear in generated code exactly in the correct sequence described in XSD?
vlad
Posted: Sunday, May 7, 2017 3:55:16 PM
Rank: Advanced Member

Joined: 12/13/2005
Posts: 2,856
Location: Mauritius
It would be a serious limitation if XML Schema would only allow primitive constructs with a single sequence of child elements.

In fact, XML Schema is so flexible (just think of combination of choice and sequence, or even a repeating sequence, all-construct, wildcards, substitution, etc), that automatically resorting output elements when writing them is not possible in 99% of cases.
econex
Posted: Monday, May 8, 2017 3:55:42 AM
Rank: Newbie

Joined: 5/4/2017
Posts: 3
Question is, how to produce syntactically valid output with Altova generated code? Are there recommended techniques? Is the use of original XSD mandatory alongside with the code? Or all relevant info on sequences is already present inside the code? Which external tools can be used to fix sequences? XSLT? XQuery?
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.