Defining xml in an xsd where an attribute determines the possible contents

你说的曾经没有我的故事 提交于 2019-12-22 06:47:15

问题


How would one go about defining something like this in an xsd?

<start>
    <request type="typeA">
        <elementOnlyFoundInA />
    </request>
    <request type="typeB">
        <elementOnlyFoundInB />
    </request>
</start>

I ran xsd.exe just to get an idea of what it might look like, but it does not appear recognize the relationships between the value of type and the contents of the request. Is it even possible to define contents based on an attribute like this in an xsd file?


回答1:


XML Schema doesn't currently support anything like this - you cannot make structure dependent on the contents of other attributes or elements.

A new XML schema version in the works might offer something in that direction, but it's far from being accepted and implemented at this time.

If you need this kind of XML validation, you need to turn to Schematron for now.



来源:https://stackoverflow.com/questions/2593325/defining-xml-in-an-xsd-where-an-attribute-determines-the-possible-contents

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!