Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XML parser: Element ordering?

23 views
Skip to first unread message

Florian Lindner

unread,
Aug 31, 2012, 8:03:16 AM8/31/12
to pytho...@python.org
Hello,

I plan to use the etree.ElementTree XML parser to parse a config file
in which the order of the elements matter, e.g.:

<A>
<C /><D />
</A>

is not equal to:

<A>
<D /><C />
</A>

I have found different answers to the question if order matters in XML
documents. So my question here: Does it matters (and is more or less
guarenteed to matter in the future) for the ElementTree parser of
python?

Thanks,

Florian

Stefan Behnel

unread,
Aug 31, 2012, 8:21:54 AM8/31/12
to pytho...@python.org
Florian Lindner, 31.08.2012 14:03:
It matters for XML documents, so, yes, any XML parser will definitely
honour the document order (which is actually well defined for an XML document).

What you might be referring to is the case of a specific XML document
format, where the application (or sometimes specification) can explicitly
state that the element order in a given subtree has no meaning for the
semantics of the element and that therefore code must ignore the order in
which elements occur. But that won't magically make the parser ignore it
for you. That's a totally different level of abstraction and a deliberate
decision of the code that *uses* the parser.

Stefan


Dave Angel

unread,
Aug 31, 2012, 8:31:17 AM8/31/12
to Stefan Behnel, pytho...@python.org
There is a place in xml documents which is defined to be unordered.
That's the attributes within one element.

<E attr3="x" attr1="y" attr2="z" />

is indistinguishable from:

<E attr2="z" attr1="y" attr3="x" />

--

DaveA

0 new messages