XSD multiple elements with same name but different types

前端 未结 1 531
北荒
北荒 2021-01-21 19:04

I\'m trying to write an XSD against some XML that looks (structurally wise) something like this:



    
        foo<         


        
相关标签:
1条回答
  • 2021-01-21 19:36

    At the design level, the question to ask is why you wish to specify two different elements with different validity conditions, and then use their element type names to say that they are the same thing. Do you believe that lying to the processor in this way is good design?

    At the schema level: the type to be assigned to an element is completely determined by the path from the validation root. (If the validation starts at the document root, then in your example the type of a response element must be completely determined by the path /responses/response. It is perfectly legal to have two elements with the same name which appear in different contexts (where 'context' is defined solely by ancestry and not by siblings); it is not allowed in XSD to have different default types for two siblings of the same name.

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