Does XML care about the order of elements?

后端 未结 7 1695
盖世英雄少女心
盖世英雄少女心 2020-11-30 10:55

XML confuses me sometimes, but I\'m trying to get this figured out. What the vendor is telling me doesn\'t make sense but again, XML and I don\'t get along :)

I have

7条回答
  •  我在风中等你
    2020-11-30 11:13

    XML schema compositor "sequence" will enforce ordering

    I know this is old but I just came upon the post.

    Until today I would most likely answer the question Does XML care about the order of elements? with No, unless you use a poorly written xml parser.

    However, today a third party application complained that the xml files I created were invalid. They use an XSD file to validate the xml. And yes, you can enforce the order or elements within an xsd file:

    
      
        
          
          
        
      
    
    

    The keyword is xs:sequence

    The sequence element specifies that the child elements must appear in a sequence. Each child element can occur from 0 to any number of times.

    which is in contrast to xs:all which does not care about the order but only allows elements which occur zero or once.

    Specifies that the child elements can appear in any order. Each child element can occur 0 or 1 time

    (The words sequence and all are both what is called a Compositor in the XML Schema definition.)

提交回复
热议问题