views:

104

answers:

2

Hi

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>
    <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

+1  A: 

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 :-)

Karussell
Nice try, but the tool generates `<xs:choice>`-elements with all stuff provided in the example xml. But I need an "open" solution
Scoregraphic
A: 

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>
Scoregraphic