Can I enforce the order of XML attributes using a schema?

后端 未结 8 1921
囚心锁ツ
囚心锁ツ 2020-12-06 10:01

Our C++ application reads configuration data from XML files that look something like this:


 

        
8条回答
  •  情书的邮戳
    2020-12-06 10:28

    Just a guess, but can you try adding use="required" to each of your attribute specifications?

    
     
     
      
      
      
     
    
    

    I'm wondering if the parser is being slowed down by allowing optional attributes, when it appears your attributes will always be there.

    Again, just a guess.

    EDIT: XML 1.0 spec says that attribute order is not significant. http://www.w3.org/TR/REC-xml/#sec-starttags

    Therefore, XSD won't enforce any order. But that doesn't mean that parsers can't be fooled into working quickly, so I'm keeping the above answer published in case it actually works.

提交回复
热议问题