4 ms·
I like XML for structured data. I also like XSL for self-documenting format to format conversion (or display). However I am going to respectfully disagree with
by Someone1234 12y ago
I like XML for structured data. I also like XSL for self-documenting format to format conversion (or display). However I am going to respectfully disagree with you about XML schemas, they suck...
XML schemas don't "understand" XML the language, and as a result you cannot use schemas unless you're using XML wrongly. For example, in XML:
<myroot>
<thing>
<name>Robot</name>
<size>15</size>
</thing>
<person>
<name>John Smith</name>
<id>12345</id>
</person>
</myroot>
And:
<myroot>
<person>
<name>John Smith</name>
<id>12345</id>
</person>
<thing>
<name>Robot</name>
<size>15</size>
</thing>
</myroot>
These two XML documents produce identical DOM and or XPaths. The fact that person and thing are inverted in the second example is irrelevant, but now try to write a schema definition which supports either thing/person or person/thing ordering.
It is possible to do with just one node switch in the above example, but convoluted. As you add more and more nodes the definition becomes unmanageable, imagine 10+ nodes on the same "level" but they can be ordered randomly, and are all required (and your schema needs to check they exist).
XML schema sucks, really sucks, when you use XML correctly and ignore node order. So if you choose to use a schema you're then forced to also require everything in an exacting order which can be problematic when XML is automatically generated from dozens of different systems or people.
XML schema sucked so bad we wrote our own replacement in Java. It just generates an XML DOM tree (via the standard libraries), then it parses your "schema" file which is just a list of XPaths with either a required, optional, or excluded flag. It is like 20 lines of code and it is better than XML Schema language.
- personZ 12y agoXML schema sucks, really sucks, when you use XML correctly and ignore node order. How is ignoring node order "correct" (and on the flip side, how is demanding an order using it "wrongly")? In many XML parser implementations, node order is reflected in the resulting DOM. Yes, a schema lets you demand that nodes come in a specific order, and this is a complete non-problem, generally -- the whole point of schemas is that they very tightly define the format, and source systems abide by it, even if that means they have to alter the generating order to be compliant.
- stonemetal 12y agoAs someone not intimately familiar with xml wouldn't xs:all do what you need? It provides unordered but required.
- Someone1234 12y agoIn theory yes. In practice absolutely no. The examples are oversimplified, and when you start using xs:all or xs:choice you quickly start running into inheritance issues (e.g. the top level node is optional, but when it exists child-XYZ are mandatory, and when you mix child optional and child mandatory things get "strange"). I spent a few days trying to get a schema working with our format. I had it working well enough with a specific node ordering, but when I tried to get it working with an order-agnostic set it would all break down around you. That's when I threw out two full days of work and replaced it with a Java class I spent about an hour writing and testing. Working flawlessly ever since.
- Mikhail_Edoshin 12y agoAs far as I understand this is a limitation of the underlying processing model (tree automata and such, although I'm not an expert). That is I suspect it would be equally hard to describe such an unordered collection of required elements using a context-free grammar. (On the other hand Relax NG seems to handle it nonetheless.)
- the_why_of_y 12y agoNo idea about "XML Schema", but it's not the only schema language and Relax NG "interleave" should do what you want. http://relaxng.org/spec-20011203.html#IDA2Z0R http://relaxng.org/spec-20011203.html#IDA2Z0R