In document order, the nodes in an XML document retain the order in which they appear in the XML document. Some elements contain other elements, and that hierarchical structure is maintained . In addition, the order of sibling nodes, at the same level in the document hierarchy, is preserved. For example, in document order, Mercury's <planet> element comes before Venus's <planet> element here: <?xml version="1.0"?> <planets> <planet> <name>Mercury</name> <mass units="(Earth = 1)">.0553</mass> <day units="days">58.65</day> <radius units="miles">1516</radius> <density units="(Earth = 1)">.983</density> <distance units="million miles">43.4</distance> <!--At perihelion--> </planet> <planet> <name>Venus</name> <mass units="(Earth = 1)">.815</mass> <day units="days">116.75</day> <radius units="miles">3716</radius> <density units="(Earth = 1)">.943</density> <distance units="million miles">66.8</distance> <!--At perihelion--> </planet> . . . In other words, document order simply refers to the order in which nodes appear in an XML document. There's no question about the order when you're dealing with elements that enclose other elements, for example, but when you're dealing with elements on the same levelsibling elementsdocument order specifies that they should be ordered as they were in the original XML document. MORE ON DOCUMENT ORDER Here's one more thing to know about document orderattribute nodes are not in any special order, even in document order. That is, document order says nothing about the order of attributes in an element. XPath also organizes nodes into node-sets as well as node trees, the next step up from simple document order. |