sequence of XML elements

J

Jonas Hei

Can someone please clarify the in which XML standard (and various parsers)
handle sequence of elements in XML?

1. Are the following two documents same (syntactically and sematically)?
a.
<Data>
<InitialQualifier>xyz</InitialQualifier>
<Value>678</Value>
<Value>524</Value>
</Data>
b.
<Data>
<InitialQualifier>xyz</InitialQualifier>
<Value>524</Value>
<Value>678</Value>
</Data>


2. Do parsers (JDOM, MSXML, etc, etc) guarantee that the sequence of
elements at a given level in hierarchy (like the <Value> elements in the
above example) will be preserved when the file is loaded,
processed(edited) and saved back?


3. Any comments on the following:
<Data>
<Year>2001</Year>
<Month>06</Month> <--implies Jun-2001-->
<Month>05</Month> <--implies May-2002-->
<Month>07</Month> <--implies Jul-2003-->
</Data>
 
M

Martin Honnen

Jonas Hei wrote:

1. Are the following two documents same (syntactically and sematically)?
a.
<Data>
<InitialQualifier>xyz</InitialQualifier>
<Value>678</Value>
<Value>524</Value>
</Data>
b.
<Data>
<InitialQualifier>xyz</InitialQualifier>
<Value>524</Value>
<Value>678</Value>
</Data>

No, the documents are not the same, the order of elements matters, see
for instance the XML information set specification
http://www.w3.org/TR/xml-infoset/#infoitem.element
2. Do parsers (JDOM, MSXML, etc, etc) guarantee that the sequence of
elements at a given level in hierarchy (like the <Value> elements in
the above example) will be preserved when the file is loaded,
processed(edited) and saved back?

In the DOM (document object model) the order of child nodes matters and
is preserved when saving back (serializing the DOM tree).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top