質問

I've heard a couple times that the XML specification indicates that XML is not ordered (e.g. if you expect order, then it's not really true XML). As far as I could find, the XML specification says nothing about the order of elements; neither that it was explicitly unordered, or suggesting that there be no order.

I already know that

But what I want to know, is: does the XML Specification (any version) say anything about order of elements?

役に立ちましたか?

解決

Yes, the XML specification cares about element order. XML document type declarations (DTDs) are a part of the XML specification. They can be used to enforce a specific order of elements. The specification explicitly talks about element orders, e.g. here:

... governing the allowed types of the child elements and the order in which they are allowed to appear.

An XML document which adheres to its DTD is considered valid.

However, if you are just talking about well-formedness, but not about validity, then the order of the elements is not important.

他のヒント

It is generally assumed that the order of child elements within a parent element is potentially significant, and that parsers will report elements in the original order to the application. However, when I last looked, the specification doesn't say so explicitly. This oversight is presumably because it was completely obvious to the spec authors, who were interested primarily in the use of XML to represent documents, where the order of paragraphs within a section clearly needs to be retained.

The specification does explicitly say that the order of attributes within an element is not significant. Perhaps that's what you were thinking of.

In a XML Schema Definition you can control this using all or sequence. Discussed here.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top