Hi all,
  I have this sample XML document:

<?xml version="1.0"?>
<data>
  <record>
    <x>foo</x>
    <y>hi</y>
    <z>something</z>
  </record>
  <record>
    <x>bar</x>
    <y>there</y>
    <u>something else</u>
  </record>
</data>

and I have written the following XML Schema for this:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>

  <xs:element name="data">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="record" type="recordType" minOccurs="0"
maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:complexType name="recordType">
    <xs:choice>
      <xs:sequence>
        <xs:element name="x" type="xs:string" fixed="foo" />
        <xs:element name="y" type="xs:string" />
        <xs:element name="z" type="xs:string" />
      </xs:sequence>
      <xs:sequence>
        <xs:element name="x" type="xs:string" fixed="bar" />
        <xs:element name="y" type="xs:string" />
        <xs:element name="u" type="xs:string" />
      </xs:sequence>
    </xs:choice>
  </xs:complexType>

</xs:schema>

What I actually want is, if value of x is foo, the 3rd element in
record should be z. While if value of x is bar, the 3rd element in
record should be u.

I thought that the sample XML shown above would be valid as per the
above Schema. But Xerces-J 2.9.1 gives the following error as a result
of validation:

java jaxp.SourceValidator -i test.xml -a test.xsd
[Error] test.xml:9:15: cvc-elt.5.2.2.2.2: The value 'bar' of element 'x' does no
t match the {value constraint} value 'foo'.
[Error] test.xml:11:8: cvc-complex-type.2.4.a: Invalid content was found startin
g with element 'u'. One of '{z}' is expected.
test.xml: 70 ms

(I am using the SourceValidator utility provided with Xerces).

My questions are:

The Schema seems to compile fine with Xerces. There is no Schema
grammar error flagged by Xerces.

1) Is it fine to use xs:choice to select one of two (or many) xs:sequence ?

2) Can this be a possible Xerces bug?

3) What will be the correct XSD 1.0 Schema for this requirement? Is
this problem solvable with XSD 1.0? If not, would XSD 1.1 bring some
features to address this issue?


-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to