将any添加到complexType

时间:2014-10-08 09:21:51

标签: xsd

我有这个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>,但似乎不允许这样做。

2 个答案:

答案 0 :(得分:2)

我无法找到一种方法来做我想做的事情,所以我最终添加了所有&#34;不需要的&#34;我的列表中的标记,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>

答案 1 :(得分:1)

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

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

否则你可以使用xs:anyType

  

xs:anyType是一个类型,如xs:integer(尽管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

<person gender="female">
  <firstname>Hege</firstname>
  <lastname>Refsnes</lastname>
</person>