Why is node order important in XML?

后端 未结 5 638
庸人自扰
庸人自扰 2021-01-05 09:48

I\'ve been dealing with an API recently that requires nodes of the XML document to be in a particular order. I was wondering why they feel the need to enforce this when I ca

5条回答
  •  青春惊慌失措
    2021-01-05 10:05

    The answer lies in XML-DTD/Schema. The underlying schema so defined in the API results in the error. Though I suppose I donot wish to teach XML here, still a look at the following will make things clear.

    XML has two points to be considered:

    • Well Formed XML: perfect syntax
    • Valid XML: perfectly valid against a DTD (Document Type Definition) / Schema

    Points about DTD: Suggested DTD upon your question:

    
    
    
    ]>
    

    The above is a suggested DTD upon the structure you provided in the question. Since you are dealing with a particular API, it has such type of structure already defined in it. Alternative to this is the XML schema.

    Points about XML Schema:

        
    
      
        
        
        
      
    
    
    

    Currently, XML schema are used instead of DTDs as they are far more superior in defining the data structure for their users and provide an object-oriented approach.

提交回复
热议问题