Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the order of two siblings implementation dependent?

If I have an XML document like this one:

<people>
    <person>
        <name> Mario </name>
        <age> 25 </age>
    </person>
    <person>
        <name> Lucas </name>
        <age> 32 </age>
    </person>
</people>

Is always guaranteed that in the document order, Mario occurs before Lucas? so Lucas is always a following sibling of Mario, or it's implementation dependent?

like image 971
Ramy Al Zuhouri Avatar asked Sep 18 '25 09:09

Ramy Al Zuhouri


1 Answers

Unlike with attributes, where order is insignificant according to the XML Recommendation:

Note that the order of attribute specifications in a start-tag or empty-element tag is not significant.

Element order is significant in XML.

However, surprisingly, the XML Recommendation makes no clear, explicit declaration regarding the significance of element order in general. The grammar implies that element ordering is significant, but, unlike for attributes, there is no explicit statement regarding the significance of the order of elements.

There is the following statement in the case of Element Type Declarations:

Definition: In this case, the constraint includes a content model, a simple grammar governing the allowed types of the child elements and the order in which they are allowed to appear.

But this is in reference to DTD element type declarations. XSDs can similarly declare that ordering is significant (via xsd:sequence) or insignificant (via xsd:all) for document validity. Order still may or may not matter to any given application -- that's up to the application. [Thanks to @C. M. Sperberg-McQueen for his helpful clarification between the difference of relevance to validity versus to any given application's purpose.]

The significance of element ordering is addressed in XML Information Set Recommendation in Section 2.2 Element Information Items:

An element information item has the following properties:

[...]

  1. [children] An ordered list of child information items, in document order. This list contains element, processing instruction, unexpanded entity reference, character, and comment information items, one for each element, processing instruction, reference to an unprocessed external entity, data character, and comment appearing immediately within the current element. If the element is empty, this list has no members.
like image 83
kjhughes Avatar answered Sep 21 '25 03:09

kjhughes