473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

XML Schema problem...

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.

Jul 20 '05 #1
4 1662
This is my schema:

<?xml version="1.0"?>
<xs:schema xmlns:xs="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>


Jul 20 '05 #2
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: <6a**************************@posting.google.com >
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
Jul 20 '05 #3
Please try whether the following work. Just re-arranged a little bit.
=============
<?xml version="1.0" ?>

<xs:schema xmlns:xs="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" <ch**@million.dp.ua> wrote in message
news:br***********@pandora.alkar.net...
This is my schema:

<?xml version="1.0"?>
<xs:schema xmlns:xs="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>

Jul 20 '05 #4
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
th******@dataloger.dk | knowledge of the position and direction
http://www.jakobnielsen.dk/ | of everything in the other tenth."
| -- Terry Pratchett, Thief of Time
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: C. M. Sperberg-McQueen | last post by:
wooks (wookiz@hotmail.com) wrote: > <?xml version='1.0'?> > <userlogin xmlns="urn:faster:userlogin" > xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> > <login>mick</login> > ...
1
by: Gregg Williams | last post by:
Hi--I am having a problem designing a schema to fit my XML data, and I'm hoping that someone can help. Essentially, I have a schema in mind and two target vocabularies for it, where one vocabulary...
4
by: Gordon Dickens | last post by:
I have target xml to generate from schema. All of the XML instances have the same global element i.e. <base>. I would like to combine all of the schemas into a single schema where I could...
5
by: Zombie | last post by:
Hi, Can I have 2 namespaces in the same XML schema? In the schema, I wish to declare elements such that some of them belong to one namespace and others belong to a second namespace. Is this...
1
by: Marcello Villani | last post by:
Hi All, I have this problem: my customer sent me a RDF file with its own schema. I absolutely need to convert that RDF schema in XML schema. Does anybody knows if this operation is possible? Can...
2
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema"...
4
by: Iain A. Mcleod | last post by:
Hi I'm stuck with the following schema validation problem in VS.NET 2003: I have two types of xml document and related schema: project and projectCollection. A projectcollection is just a set...
2
by: Ali | last post by:
I am having problem compiling schema contained in WSDL file when analyzing schema types contained in it (for example http://www.ebout.net/net/GoogleSearch.wsdl). Following code demonstrates my...
5
by: paul_zaoldyeck | last post by:
does anyone know how to validate an xml file against multiple defined schema? can you show me some examples? i'm making here an xml reader.. thank you
2
by: yannick.beot | last post by:
Hi, I have a problem with nested namespace in a schema. I defined a schema A. A is importing a schema B with the namespace nsB and a schema C with the namespace nsC. But both B and C are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.