Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML Schema problem...

Reply
Thread Tools

XML Schema problem...

 
 
Andrew
Guest
Posts: n/a
 
      12-18-2003
Antony (4:26 PM) :
Hello all !

I have a problem with XML schema.

My XML document which I need to be validated
can be one of the following two types:

1st type is

<?xml version="1.0"?>
<response>
<msg_id>100</msg_id>
<command>Command1</command>
<time>100</time>
<b>text</b>
</response>


2nd type is

<?xml version="1.0"?>
<response>
<msg_id>100</msg__id>
<command>Command2</command>
<sometag>content</sometag>
<time>789012</time>
<a>text</a>
</response>


Note that content of the "command" element
is used to determine the rest of elements. Thus
"Command1" means that there should be "time" and "b" elements,
and "Command2" means that there should be "sometag", "time", and "a"
elements.

When trying to load the schema both xerces and msxml parsers
return me error message: "Unique Particle Attribution rule".

How should correct schema look ?
Can anyone help ?

Thanks in advance.



 
Reply With Quote
 
 
 
 
Andrew
Guest
Posts: n/a
 
      12-18-2003
This is my schema:

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

<xs:element name="response" type="respType"/>

<xs:complexType name="respType">
<xs:choice>
<xs:group ref="g1"/>
<xs:group ref="g2"/>
</xs:choice>
</xs:complexType>

<xs:group name="g1">
<xs:sequence>
<xs:element name="msg_id" type="xs:int"/>
<xs:element name="command" type="xs:string"/>
<xs:element name="time" type="xs:int"/>
<xs:element name="b" type="xs:string"/>
</xs:sequence>
</xs:group>

<xs:group name="g2">
<xs:sequence>
<xs:element name="msg_id" type="xs:int"/>
<xs:element name="command" type="xs:string"/>
<xs:element name="sometag" type="xs:string"/>
<xs:element name="time" type="xs:int"/>
<xs:element name="a" type="xs:string"/>
</xs:sequence>
</xs:group>

</xs:schema>




 
Reply With Quote
 
 
 
 
Sean Bright
Guest
Posts: n/a
 
      12-18-2003
Andrew wrote:

> Note that content of the "command" element
> is used to determine the rest of elements. Thus
> "Command1" means that there should be "time" and "b" elements,
> and "Command2" means that there should be "sometag", "time", and "a"
> elements.


I'm not sure this type of conditional processing is possible with XML
Schemas. See the the following thread in this newsgroup for something
slightly similar:

Message ID: <(E-Mail Removed) >
From: Ralf Wahner
Subject: Schema express that "@a present if and only if @b present",
where @a, @b are attributes

The relevant portion of that thread is:

>> As I'm new to XML Schema I dare to ask a possibly recurring
>> question: Given an element <elem> with two attributes @a and
>> @b. The attributes are bound by the condition, that either both
>> or none must be present, i.e.

>
> That is not possible with W3C's xml schema.


Apparently something like this is possible with RELAX NG, but I wouldn't
know about that.

Hope this helps,
Sean
 
Reply With Quote
 
strajan
Guest
Posts: n/a
 
      12-18-2003
Please try whether the following work. Just re-arranged a little bit.
=============
<?xml version="1.0" ?>

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

<xs:element name="response" type="respType" />

<xs:complexType name="respType">

<xs:sequence>

<xs:element name="msg_id" type="xs:int" />

<xs:element name="command" type="xs:string" />

<xs:choice>

<xs:group ref="g1" />

<xs:group ref="g2" />

</xs:choice>

</xs:sequence>

</xs:complexType>

<xs:group name="g1">

<xs:sequence>

<xs:element name="time" type="xs:int" />

<xs:element name="b" type="xs:string" />

</xs:sequence>

</xs:group>

<xs:group name="g2">

<xs:sequence>

<xs:element name="sometag" type="xs:string" />

<xs:element name="time" type="xs:int" />

<xs:element name="a" type="xs:string" />

</xs:sequence>

</xs:group>

</xs:schema>

================

"Andrew" <(E-Mail Removed)> wrote in message
news:brprcb$2uc1$(E-Mail Removed)...
> This is my schema:
>
> <?xml version="1.0"?>
> <xs:schema xmlnss="http://www.w3.org/2001/XMLSchema">
>
> <xs:element name="response" type="respType"/>
>
> <xs:complexType name="respType">
> <xs:choice>
> <xs:group ref="g1"/>
> <xs:group ref="g2"/>
> </xs:choice>
> </xs:complexType>
>
> <xs:group name="g1">
> <xs:sequence>
> <xs:element name="msg_id" type="xs:int"/>
> <xs:element name="command" type="xs:string"/>
> <xs:element name="time" type="xs:int"/>
> <xs:element name="b" type="xs:string"/>
> </xs:sequence>
> </xs:group>
>
> <xs:group name="g2">
> <xs:sequence>
> <xs:element name="msg_id" type="xs:int"/>
> <xs:element name="command" type="xs:string"/>
> <xs:element name="sometag" type="xs:string"/>
> <xs:element name="time" type="xs:int"/>
> <xs:element name="a" type="xs:string"/>
> </xs:sequence>
> </xs:group>
>
> </xs:schema>
>
>
>
>



 
Reply With Quote
 
Jakob Møbjerg Nielsen
Guest
Posts: n/a
 
      12-21-2003
Andrew wrote:
> <xs:element name="command" type="xs:string"/>
> <xs:element name="command" type="xs:string"/>


Sorry about the late answer, but why not create your own types with a
pattern restriction?

Blatantly stolen from http://www.w3.org/TR/xmlschema-2/#rf-pattern:

<simpleType name=command1>
<restriction base='string'>
<pattern value='Command1'/>
</restriction>
</simpleType>

<simpleType name='command2'>
<restriction base='string'>
<pattern value='Command2'/>
</restriction>
</simpleType>

--
Jakob Møbjerg Nielsen | "Nine-tenths of the universe is
http://www.velocityreviews.com/forums/(E-Mail Removed) | knowledge of the position and direction
http://www.jakobnielsen.dk/ | of everything in the other tenth."
| -- Terry Pratchett, Thief of Time


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
web.xml / XML schema issue, why do some XML schema attributes disappear asciz@starmail.com Java 3 02-20-2007 09:56 AM
Validation with XSD using XML::LibXML::Schema, and XML::Validator::Schema huntingseasonson@gmail.com Perl Misc 5 11-29-2006 12:37 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
XML Schema to XML Schema Conversion Hari Om XML 1 03-02-2004 09:04 PM
XML schema regular expressions question and recommended XML Schema book Fred Smith XML 1 02-05-2004 11:12 AM



Advertisments