Question about XML-Schema choice structure.

GB

Usenet Archive
Joined
Mar 16, 2000
Messages
103
Reaction score
0
If I define the following schema which allows either a tag element OR an tag and origin_system elements I get an error. Same thing happens when I use groups. Is this because tag is defined twice? My reading of the XML-Schema spec seems to suggest that the schema is valid & that Xerces is in error.

I get the error with Java Xerces 2.3.0 but not with C++ Xerces 1.7.0.

Can anyone explain?

Here's the error...

error [4,16] cvc-complex-type.2.4.a: Invalid content starting with element 'origin_system'. The content must match '((("":tag))|(("":tag),("":eek:rigin_system)))'.

Here's the schema....

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:element name="fx" type="fx_type"/>

<xsd:complexType name="fx_type">
<xsd:choice>
<xsd:sequence>
<xsd:element name="tag" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:sequence> <xsd:sequence> <xsd:element name="tag" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="origin_system" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:choice> </xsd:complexType>

</xsd:schema>

Heres the XML...

<?xml version="1.0" encoding="UTF-8"?>
<fx>
<tag>$0000000002275ABD</tag>
<origin_system>PAB</origin_system>
</fx>
 

Eric Sirois

Usenet Archive
Joined
Jun 28, 2001
Messages
64
Reaction score
0
Hello,

The reason that Xerces is giving you an error it that it cannot determine whether or not the element <tag> belongs to the first or second sequence.

Try the following
<sequence>
<element name="tag" />
<element name="origin_system" minOccurs="0" maxOccurs="1"/> <sequence>

So, fx_type can simply have a <tag> element or <tag> and <origin_systemt>, but tag must appear first in the XML document.

Hope this helps.

Kind regards
Eric

GB wrote:

If I define the following schema which allows either a tag element OR an tag and origin_system elements I get an error. Same thing happens when I use groups. Is this because tag is defined twice? My reading of the XML-Schema spec seems to suggest that the schema is valid & that Xerces is in error.

I get the error with Java Xerces 2.3.0 but not with C++ Xerces 1.7.0.

Can anyone explain?

Here's the error...

...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,798
Members
249,594
Latest member
henrywalsh

Latest Threads

Top