Question

I have a xml in following format

<abc>
  <xyz name="all">
    <last a="1" b="2"></last>
    <last a="1" b="2"></last>
  </xyz>
  <xyz name="el">
    <last a="1" b="2"></last>
    <last a="1" b="2"></last>
  </xyz>
  <xyz name="els">
    <last a="1" b="2"></last>
    <last a="1" b="2"></last>
  </xyz>
</abc>

For this i have written a xsd something like this

<xsd:element name="abc" type="abcType" />
  <xsd:complexType name="abcType">
    <xsd:sequence>
      <xsd:element maxOccurs="unbounded" name="xyz" type="xyzType" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="xyzType">
    <xsd:sequence>
      -----
    </xsd:sequence>
    <xsd:attribute name="name" type="xsdLocal:nameType" use="required"/>
  </xsd:complexType>
  <xsd:simpleType name="nameType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="ALL|[a-z]*"/>
    </xsd:restriction>
 </xsd:simpleType>

But my question is how to check "xyz" with "name" attribute value "all" always come first and optional.

Please help... Thanks in advance.

Was it helpful?

Solution

But my question is how to check "xyz" with "name" attribute value "all" always come first and optional.

You can't do this with XSD 1.0. The grammar defined for a complex type only constraints elements in the sequence by their element name, not by their content, and the rules for the content of an element cannot differ for two sibling elements with the same name.

You can do it, of course, with XSD 1.1 assertions. For example, a constraint at the level of the containing abc element of the form assert="not(xyz[@name='all']/preceding-sibling::*)".

XSD 1.1 is currently implemented only in Saxon and Xerces.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top