开发者

Invalid XML Schema for element with/without sub-elements

I want to write an XML schema which has an element which may contain subelements and/or primitive types. So I have this fragment which does not validate correctly.

  <xs:complexType name="parameterType" mixed="true">
    <xs:complexContent>
      <xs:restriction base="xsd:anyType">
        <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
        <xs:attribute name="name" type="xs:string" use="required" />
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>

  <xs:element name="parameters">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="parameter" type="my:parameterType" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

XML would look like (I really have no clue what the value is)

  <parameters>
    <parameter name="interval">10000</parameter>
    <parameter name="active">true</parameter>
    <开发者_StackOverflow社区;parameter name="list"><items><item>a</item><item>b</item></items></parameter>
    <parameter name="article"><article><title>a</title><price>10.00</price></article></parameter>
    ...
  </parameters>

Thanks for any help


You can use a no-brainer trick: create your schema from an xml example file via this explanation (which uses trang) and compare to your current schema :-)


Ok, I got it by myself. I have now this working solution:

  <xs:complexType name="parameterType" mixed="true">
    <xs:complexContent>
      <xs:restriction base="xs:anyType">
        <xs:sequence>
          <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:attribute name="name" type="xs:string" use="required" />
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜