2014-10-08 70 views
2

我有这样的XML架构:任何添加到复杂类型

<xs:element name="lineinfo"> 
     <xs:complexType> 
     <xs:all> 
      <xs:element name="done" type="xs:unsignedInt" /> 
     </xs:all> 
     <xs:attribute name="id" type="xs:long" /> 
     <xs:anyAttribute processContents="skip" /> 
     </xs:complexType> 
    </xs:element> 

,但我想允许任何其他额外的元素在lineinfo标签:

<lineinfo state="assigned" id="175"> 
     <done>4</done> 
     <todo>6</todo> 
    </lineinfo> 

我尝试添加<xs:any /><xs:all>内,但它似乎不被允许。

回答

1

<xs:any>的父标签仅为choicesequencew3cschools #el_any

要使用<xs:any>请将<xs:sequence>代替<xs:all>w3cschools #any

否则你可以使用的xs:anyType的

的xs:anyType的是一种类型的,像XS:整数(虽然XS:anyType的是,它可以作为一个简单的或复杂类型行动特别 ,和它将 对它验证的树进行基本上的限制 - 将它看作是Schema语言的java.lang.Object模拟的松散的 )。

的样本用法是:

<xsd:element name="value" type="xs:anyType"/> 

无论如何,如果你想使用下面从w3cschools #anyattribute

SCHEMA

<xs:element name="person"> 
    <xs:complexType> 
    <xs:sequence> 
     <xs:element name="firstname" type="xs:string"/> 
     <xs:element name="lastname" type="xs:string"/> 
    </xs:sequence> 
    <xs:anyAttribute/> 
    </xs:complexType> 
</xs:element> 

<xs:attribute name="gender"> 
    <xs:simpleType> 
    <xs:restriction base="xs:string"> 
     <xs:pattern value="male|female"/> 
    </xs:restriction> 
    </xs:simpleType> 
</xs:attribute> 

XML

采取的一个例子0
<person gender="female"> 
    <firstname>Hege</firstname> 
    <lastname>Refsnes</lastname> 
</person> 
+0

我得到的,但'sequence'将描述元素的顺序。我想要订单是免费的。 – 2014-10-08 10:07:45

+0

是的,你是对的。您是否尝试过为您的解决方案使用xs:anyType,以便移除xs:sequence。 – Xstian 2014-10-08 10:10:13

+0

我仍然需要标签的名称。我只是希望模式验证'done'是在'lineinfo'里面,并忽略其中的任何其他标签。 – 2014-10-08 10:12:39

2

我无法找到一个方法来做到我想要的东西,所以我最终将所有“不必要的”标签在我的名单,与minOccurs设置为0:

<xs:element name="lineinfo"> 
     <xs:complexType> 
     <xs:all> 
      <xs:element name="done" type="xs:unsignedInt" /> 
      <xs:element name="todo" minOccurs="0" /> 
      <xs:element name="error" minOccurs="0" /> 
     </xs:all> 
     <xs:attribute name="id" type="xs:long" /> 
     <xs:anyAttribute processContents="skip" /> 
     </xs:complexType> 
    </xs:element>