XSD 和 xmllint:用 xs:all 替换 xs:sequence 会出错
XSD and xmllint : replacing xs:sequence with xs:all gives an error
我想验证以下 XML,而不强加点的顺序 :
<?xml version='1.0' encoding='ISO-8859-1'?>
<root>
<name>Map corners</name>
<point>NW</point>
<point>SW</point>
<point>NE</point>
<point>SE</point>
</root>
我的 XSD 是:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="point" type="xs:string" fixed="NW"/>
<xs:element name="point" type="xs:string" fixed="SW"/>
<xs:element name="point" type="xs:string" fixed="NE"/>
<xs:element name="point" type="xs:string" fixed="SE"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
xmllint 验证了我的 XML.
但是如果我将 xs:sequence 替换为 xs:all(以释放顺序约束:SW 可能在 NW 之前),它不会验证,并且我有以下消息:
my6.xsd:4: 元素复杂类型:模式解析器错误:本地复杂类型:内容模型不是确定性的。
我是不是漏掉了什么?
在 XSD 1.0 中,您不能将 xsd:any 与重复元素粒子一起使用。你可以这样做:
<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="point" minOccurs="4" maxOccurs="4">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="NW"/>
<xs:enumeration value="SW"/>
<xs:enumeration value="NE"/>
<xs:enumeration value="SE"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="pk_points">
<xs:selector xpath="point"/>
<xs:field xpath="."/>
</xs:key>
</xs:element>
</xs:schema>
我想验证以下 XML,而不强加点的顺序 :
<?xml version='1.0' encoding='ISO-8859-1'?>
<root>
<name>Map corners</name>
<point>NW</point>
<point>SW</point>
<point>NE</point>
<point>SE</point>
</root>
我的 XSD 是:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="point" type="xs:string" fixed="NW"/>
<xs:element name="point" type="xs:string" fixed="SW"/>
<xs:element name="point" type="xs:string" fixed="NE"/>
<xs:element name="point" type="xs:string" fixed="SE"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
xmllint 验证了我的 XML.
但是如果我将 xs:sequence 替换为 xs:all(以释放顺序约束:SW 可能在 NW 之前),它不会验证,并且我有以下消息:
my6.xsd:4: 元素复杂类型:模式解析器错误:本地复杂类型:内容模型不是确定性的。
我是不是漏掉了什么?
在 XSD 1.0 中,您不能将 xsd:any 与重复元素粒子一起使用。你可以这样做:
<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="point" minOccurs="4" maxOccurs="4">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="NW"/>
<xs:enumeration value="SW"/>
<xs:enumeration value="NE"/>
<xs:enumeration value="SE"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="pk_points">
<xs:selector xpath="point"/>
<xs:field xpath="."/>
</xs:key>
</xs:element>
</xs:schema>