2015-03-19 52 views
1

我想驗證以下XML,而不強加點的順序:XSD和xmllint:更換XS:與XS順序:所有的給出錯誤

<?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:與XS序列:所有(下達訂單約束:SW可以NW)之前,它不驗證,我有以下消息:

my6.xsd: 4:元素complexType:模式解析器錯誤:本地複雜類型:內容模型不是確定性的。

我錯過了什麼嗎?

回答

1

在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> 
+0

謝謝Petru。添加身份約束有助於避免例如NW,NW,NW,SE。這意味着:「此(。)」點「必須是唯一的」(使用xs:key和xs:unique幾乎相同)。另見:http://docstore.mik.ua/orelly/xml/schema/ch09_02.htm – 2015-03-23 12:17:08