xml - XSD:非此即彼语法

标签 xml xsd switch-statement

我如何在 XSD 中进行任一/或验证?例如在以下 xml 片段中,如果 actionA (add),则后续属性和元素是 required :

<Post postID="22793" action="A" ...>
   <Transaction ...>
      <Disposition ...>
         <AccountInformation ... />
         <ThirdPartyInformation ... />
      </Disposition>
      <IndividualInformation ... />
   </Transaction>

   ...
</Post>

但是如果操作D,那么后续属性和属性将被禁止::

<Post postID="22793" action="D" />

也就是说:如果操作删除 (D),则其余属性将从

  • 必填

  • 禁止

随后的元素切换自

minOccurences="1" maxOccurrences="unbounded"

minOccurrences="0" maxOccurrences="0"

是否可以使用XSD来定义xml结构?

最佳答案

the big criticisms of XSD 之一是它的失败

...provide no facilities to state that the value or presence of one attribute is dependent on the values or presence of other attributes (so-called co-occurrence constraints).

因此它无法指定像您所描述的那样的约束。在大多数情况下,我见过一些项目使用 XSLT 来验证 XSD 失败的文档。然而other Schema languages确实存在,并且您可能会通过它们获得更多成功。我听说有些人改用 Relax NG由于各种原因。

关于xml - XSD:非此即彼语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4208477/

相关文章:

mysql - 在 MySQL 表列中提取 XML

xml - 使用凭据的 Spring MongoDB XML 配置失败

iPhone Packager AS3 无法转换 switch case 语句?

c# - datagridview 事件的枚举索引

swift - 重构开关语句

c++ - 将 C++ 中的两个 xpath_node_set 与 pugixml 1.4 进行比较

JavaScript xml 查询

java - fatal error :1:1: Content is not allowed in prolog. org.xml.sax.SAXParseException

xml - 在 Visual Studio (2013) 中定义 'CustomDictionary.xml' 模式的正确方法?

xml - IXMLDocument 无法读取数据,因为 IXMLNode.Text 属性始终为空