Does XML care about the order of elements?

后端 未结 7 1660
盖世英雄少女心
盖世英雄少女心 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:29

    XML schemas can enforce element order. If there's no schema, neither order nor tags nor general structure not the kind of text (if it's a number or anything) is prescribed in any way - in theory. Of course that's not the case here.

    It is perfectly possible to parse* data from XML without caring about order, but it can be easier (e.g. when using SAX, I imagine, or when you're a lazy bastard writing very sloppy code) to parse if you assume a certain order. Although they should include some schema if they want a certain order, it's perfectly possible that their parser chokes on it anyway. Yes, they shouldn't do this, but obviously they don't care.

    *By "parsing" I don't mean "take that XML document and turn it into e.g. a DOM", but "take that e.g. DOM and extract the information from it".

    0 讨论(0)
提交回复
热议问题