在 xsd 中定义 xml,其中属性确定可能的内容 [英] Defining xml in an xsd where an attribute determines the possible contents

查看:22
本文介绍了在 xsd 中定义 xml,其中属性确定可能的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 xsd 中定义这样的东西?

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

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

我运行 xsd.exe 只是为了了解它的外观,但它似乎无法识别 type 的值与请求内容之间的关系.甚至可以在 xsd 文件中根据这样的属性定义内容吗?

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?

推荐答案

XML Schema 目前不支持这样的任何东西 - 您不能使结构依赖于其他属性或元素的内容.

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

正在开发中的新 XML 模式版本可能会朝这个方向提供一些帮助,但目前还远未被接受和实施.

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.

如果您需要这种 XML 验证,您现在需要求助于 Schematron.

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

这篇关于在 xsd 中定义 xml,其中属性确定可能的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆