【问题标题】:Separate xs:unique from element将 xs:unique 从元素中分离出来
【发布时间】:2014-12-09 19:10:19
【问题描述】:

我已获得我的 XML 需要符合的 XSD。 XSD 不包含唯一 ID 约束。

在下面的示例中,我在一行中添加了唯一 ID 约束。

<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="Passengers"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element ref="passenger"/> </xs:choice> </xs:complexType> <xs:unique name="PassengerUniqueSequnceNo"> <xs:selector xpath="./passenger"/> <xs:field xpath="@SequenceNo"/> </xs:unique> </xs:element> <xs:element name="passenger"> <xs:complexType> <xs:sequence> <xs:element name="FullName" type="xs:string"/> </xs:sequence> <xs:attribute name="SequenceNo" type="xs:int"/> </xs:complexType> </xs:element> </xs:schema>

我不想将其添加到行中。目标是通过将约束添加到不同的文件并导入/包含它来最小化对 XSD 定义的更改。

有人知道怎么做吗?

【问题讨论】:

    标签: xml xsd unique unique-constraint


    【解决方案1】:

    在 XSD 1.1 中,您可以使用 xs:override 覆盖元素声明(但您仍然必须重复元素声明中未更改的部分。)

    否则,请编写一个 XSLT 转换,在使用模式进行验证之前将约束添加到模式中。

    或者编写一个验证器(使用您喜欢的任何技术,例如 XSLT)来检查唯一性约束,并在进行架构验证后将其作为单独的传递运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      • 2012-09-19
      • 2019-06-01
      • 1970-01-01
      • 2022-12-18
      相关资源
      最近更新 更多