You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Mukul Gandhi <ga...@gmail.com> on 2008/05/23 18:26:28 UTC

Problem running a Schema with Xerces-J

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: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Problem running a Schema with Xerces-J

Posted by Mukul Gandhi <ga...@gmail.com>.
Thanks, Michael for the answer to my question. It helps me.

On Fri, May 23, 2008 at 11:17 PM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> Hi Mukul,
>
> Your schema is invalid. It violates the "Unique Particle Attribution" [1]
> constraint:
>
> [Error] test.xsd:12:37: cos-nonambig: x and x (or elements from their
> substitution group) violate "Unique Particle Attribution". During validation
> against this schema, ambiguity would be created for those two particles.
>
> You need to turn on the schema full checking feature [2] with the -f option
> in order for this constraint to be checked. It's disabled by default.
>
> You can't write a legal schema document to achieve what you want with XML
> Schema 1.0 but I imagine you could with XML Schema 1.1 by using assertions
> [3].
>
> Thanks.
>
> [1] http://www.w3.org/TR/xmlschema-1/#cos-nonambig
> [2]
> http://xerces.apache.org/xerces2-j/features.html#validation.schema-full-checking
> [3] http://www.w3.org/TR/xmlschema11-1/#cAssertions
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org


-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Problem running a Schema with Xerces-J

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mukul,

Your schema is invalid. It violates the "Unique Particle Attribution" [1]
constraint:

[Error] test.xsd:12:37: cos-nonambig: x and x (or elements from their
substitution group) violate "Unique Particle Attribution". During
validation against this schema, ambiguity would be created for those two
particles.

You need to turn on the schema full checking feature [2] with the -f option
in order for this constraint to be checked. It's disabled by default.

You can't write a legal schema document to achieve what you want with XML
Schema 1.0 but I imagine you could with XML Schema 1.1 by using assertions
[3].

Thanks.

[1] http://www.w3.org/TR/xmlschema-1/#cos-nonambig
[2]
http://xerces.apache.org/xerces2-j/features.html#validation.schema-full-checking
[3] http://www.w3.org/TR/xmlschema11-1/#cAssertions

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

"Mukul Gandhi" <ga...@gmail.com> wrote on 05/23/2008 12:26:28 PM:

> 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: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org