【发布时间】:2018-08-01 19:01:24
【问题描述】:
我在 XSD 中尝试过断言,但出现错误
元素“断言”无效、放错位置或过于频繁地出现。
我的例子是下面的 XML。
`<?xml version="1.0" encoding="utf-8"?>
<p:CustomerElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<recordCount>1234</recordCount>
<Customer>
<indicator>A</indicator>
<test1>hdjfs</test1>
<test2>idsfh</test2>
<test3>idsfh</test3>
<test4>idsfh</test4>
<test5>idsfh</test5>
<test6>idsfh</test6>
<test7>idsfh</test7>
</Customer>
<Customer>
<indicator>D</indicator>
<test1>abcd</test1>
<test3>jhf</test3>
</Customer>
</p:CustomerElement>`
我为此创建的 XSD 是
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://My.Schema.Namespace"
targetNamespace="http://My.Schema.Namespace"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
elementFormDefault="qualified"
vc:minVersion="1.1">>
<xs:element name="customer">
<xs:complexType>
<xs:sequence>
<xs:element name="indicator">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="A" />
<xs:enumeration value="B" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:choice>
<xs:element name="test1" />
<xs:element name="test2" />
<xs:element name="test3" />
<xs:element name="test4" />
<xs:element name="test5" />
<xs:element name="test6" />
<xs:element name="test7" />
</xs:choice>
</xs:sequence>
<xs:assert test="if(indicator eq 'A') then test1 and test2 and test3 and test4
and test5 and test6 and test7
else if(indicator eq 'B') then test1 and test3"/>
</xs:complexType>
</xs:element>
</xs:schema>
我在freeformat validator 中使用 XSD 验证上述 xml。
我猜断言的语法中几乎没有错误。任何人都可以就我正在寻找的条件提供帮助并在语法方面帮助我,如果我添加了支持 XSD 1.1 架构的正确链接,请告诉我。
【问题讨论】:
-
@kjhughes 你能帮我这个案子吗?
标签: xml xsd xml-parsing xsd-validation xsd-1.1