sequence of XML elements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonas Hei

    sequence of XML elements

    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>
    <InitialQualifi er>xyz</InitialQualifie r>
    <Value>678</Value>
    <Value>524</Value>
    </Data>
    b.
    <Data>
    <InitialQualifi er>xyz</InitialQualifie r>
    <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(edite d) 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>


  • Martin Honnen

    #2
    Re: sequence of XML elements



    Jonas Hei wrote:

    [color=blue]
    > 1. Are the following two documents same (syntactically and sematically)?
    > a.
    > <Data>
    > <InitialQualifi er>xyz</InitialQualifie r>
    > <Value>678</Value>
    > <Value>524</Value>
    > </Data>
    > b.
    > <Data>
    > <InitialQualifi er>xyz</InitialQualifie r>
    > <Value>524</Value>
    > <Value>678</Value>
    > </Data>[/color]

    No, the documents are not the same, the order of elements matters, see
    for instance the XML information set specification

    [color=blue]
    > 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(edite d) and saved back?[/color]

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



    --

    Martin Honnen

    Comment

    Working...