473,396 Members | 2,039 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,396 software developers and data experts.

How to do a choice on aggregation with XML schema

Hello:
( Please redirect me to the correct list if this is not where I m
supposed to
ask this question )

Our application essentially sends xml 'commands' to another system.

These commands are essentially one xml element signifying which
command it is (
3 types of commands ) and a corresponding data required by that
command.
Because some different teams are involved, we do not have freedom to
change the
XML structure ( xml vocabulary )
XML appears in one of the following 3 forms

<COMMAND>REQUEST1</COMMAND>
<COMMAND_DATA>
<REQ1_DAT1> something </REQ1_DAT1>
<REQ1_DAT2> something </REQ1_DAT2>
....
</COMMAND_DATA>

or

<COMMAND>REQUEST2</COMMAND>
<COMMAND_DATA>
<REQ2_DAT1> something </REQ2_DAT1>
<REQ2_DAT2> something </REQ2_DAT2>
<REQ2_DAT3> something </REQ2_DAT3>
....
</COMMAND_DATA>

or

<COMMAND>REQUEST3</COMMAND>
<COMMAND_DATA>
<REQ3_DAT1> something </REQ3_DAT1>

....
</COMMAND_DATA>
We need to essentially build a schema that will restrict the xml to be
in one
of these 3 forms. Is it possible to do this at all.

I had trouble defining it as the definition for COMMAND_DATA is
changing
depending on what the COMMAND is.

I tried something like

<xs:simpleType name="req1Typ">
<xs:restriction base="xs:string">
<xs:pattern value="REQUEST1"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="req2Typ">
<xs:restriction base="xs:string">
<xs:pattern value="REQUEST2"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="req1Typ">
<xs:restriction base="xs:string">
<xs:pattern value="REQUEST2"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name req1DatTyp>
<xs:sequence>
<xs:element name="REQ1_DAT1"/>
<xs:element name="REQ1_DAT2"/>
...
<xs:sequence>
</xs:complexType>

<xs:complexType name req2DatTyp>
<xs:sequence>
<xs:element name="REQ2_DAT1"/>
<xs:element name="REQ2_DAT2"/>
<xs:element name="REQ2_DAT3"/>
...
<xs:sequence>
</xs:complexType>

<xs:complexType name req3DatTyp>
<xs:sequence>
<xs:element name="REQ3_DAT1"/>
...
<xs:sequence>
</xs:complexType>
<xs:complexType name="choice_on_aggregation" >
<xs:choice>
<xs:sequence>
<xs:element name="COMMAND" type="req1Typ">
<xs:element name="COMMAND_DATA" type="req1DatTyp">
</xs:sequence>
<xs:sequence>
<xs:element name="COMMAND" type="req2Typ">
<xs:element name="COMMAND_DATA" type="req1DatTyp">
</xs:sequence>
<xs:sequence>
<xs:element name="COMMAND" type="req3Typ">
<xs:element name="COMMAND_DATA" type="req1DatTyp">
</xs:sequence>
</xs:choice>
</xs:complexType>

<element name"GLOBAL" type="choice_on_aggregation"/>
But though my xml editor ( xmlspy ) reported this to be a valid
schema, when I
used its 'generate sample XML' feature, it ended up generating xml
that did not
comply with the schema !!
When I used xerces to validate I got an error like

"http://www.bellsouth.com/wfaif":COMMAND and
"http://www.bellsouth.com/wfaif":COMMAND (or elements from their
substitution group) violate "Unique Particle Attribution". During
validation against this schema, ambiguity would be created for those
two particles"

Any help will be greatly appreciated
Thanks
--sony
Jul 20 '05 #1
3 1703
so********@hotmail.com (Sony Antony) wrote in message news:<3e**************************@posting.google. com>...
Hello:
( Please redirect me to the correct list if this is not where I m
supposed to
ask this question )

Our application essentially sends xml 'commands' to another system.

These commands are essentially one xml element signifying which
command it is (
3 types of commands ) and a corresponding data required by that
command.
Because some different teams are involved, we do not have freedom to
change the
XML structure ( xml vocabulary )
XML appears in one of the following 3 forms

<COMMAND>REQUEST1</COMMAND>
<COMMAND_DATA>
<REQ1_DAT1> something </REQ1_DAT1>
<REQ1_DAT2> something </REQ1_DAT2>
...
</COMMAND_DATA>

or

<COMMAND>REQUEST2</COMMAND>
<COMMAND_DATA>
<REQ2_DAT1> something </REQ2_DAT1>
<REQ2_DAT2> something </REQ2_DAT2>
<REQ2_DAT3> something </REQ2_DAT3>
...
</COMMAND_DATA>

or

<COMMAND>REQUEST3</COMMAND>
<COMMAND_DATA>
<REQ3_DAT1> something </REQ3_DAT1>

...
</COMMAND_DATA>
We need to essentially build a schema that will restrict the xml to be
in one
of these 3 forms. Is it possible to do this at all.


Looks like it is impossible using w3C schema
( http://www.w3.org/TR/xmlschema-1/#non-ambig )

It also turns out that w3c schema is not capable of doing conditionals
in general - like "elements a,b,c should be present if the value of
this other element is this"

That fells like a huge shortcoming on the expressive nature of w3c
schema. I hear that Relax NG is capable of doing such things. But we
dont have that liberty.

--sony





I had trouble defining it as the definition for COMMAND_DATA is
changing
depending on what the COMMAND is.

I tried something like

<xs:simpleType name="req1Typ">
<xs:restriction base="xs:string">
<xs:pattern value="REQUEST1"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="req2Typ">
<xs:restriction base="xs:string">
<xs:pattern value="REQUEST2"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="req1Typ">
<xs:restriction base="xs:string">
<xs:pattern value="REQUEST2"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name req1DatTyp>
<xs:sequence>
<xs:element name="REQ1_DAT1"/>
<xs:element name="REQ1_DAT2"/>
...
<xs:sequence>
</xs:complexType>

<xs:complexType name req2DatTyp>
<xs:sequence>
<xs:element name="REQ2_DAT1"/>
<xs:element name="REQ2_DAT2"/>
<xs:element name="REQ2_DAT3"/>
...
<xs:sequence>
</xs:complexType>

<xs:complexType name req3DatTyp>
<xs:sequence>
<xs:element name="REQ3_DAT1"/>
...
<xs:sequence>
</xs:complexType>
<xs:complexType name="choice_on_aggregation" >
<xs:choice>
<xs:sequence>
<xs:element name="COMMAND" type="req1Typ">
<xs:element name="COMMAND_DATA" type="req1DatTyp">
</xs:sequence>
<xs:sequence>
<xs:element name="COMMAND" type="req2Typ">
<xs:element name="COMMAND_DATA" type="req1DatTyp">
</xs:sequence>
<xs:sequence>
<xs:element name="COMMAND" type="req3Typ">
<xs:element name="COMMAND_DATA" type="req1DatTyp">
</xs:sequence>
</xs:choice>
</xs:complexType>

<element name"GLOBAL" type="choice_on_aggregation"/>
But though my xml editor ( xmlspy ) reported this to be a valid
schema, when I
used its 'generate sample XML' feature, it ended up generating xml
that did not
comply with the schema !!
When I used xerces to validate I got an error like

"http://www.bellsouth.com/wfaif":COMMAND and
"http://www.bellsouth.com/wfaif":COMMAND (or elements from their
substitution group) violate "Unique Particle Attribution". During
validation against this schema, ambiguity would be created for those
two particles"

Any help will be greatly appreciated
Thanks
--sony

Jul 20 '05 #2
so********@hotmail.com (Sony Antony) wrote in message news:<3e**************************@posting.google. com>...
Looks like it is impossible using w3C schema
( http://www.w3.org/TR/xmlschema-1/#non-ambig )

It also turns out that w3c schema is not capable of doing conditionals
in general - like "elements a,b,c should be present if the value of
this other element is this"


Suggest you pose your problem to the folks that lurk on the
xmlschema-dev list (lists.w3c.org). There may be a workaround
for this "constrait".

- Finnbarr
Jul 20 '05 #3
so********@hotmail.com (Sony Antony) writes:
Our application essentially sends xml 'commands' to another system.

These commands are essentially one xml element signifying which
command it is ( 3 types of commands ) and a corresponding data
required by that command. Because some different teams are
involved, we do not have freedom to change the XML structure ( xml
vocabulary ) XML appears in one of the following 3 forms

<COMMAND>REQUEST1</COMMAND>
<COMMAND_DATA>
<REQ1_DAT1> something </REQ1_DAT1>
<REQ1_DAT2> something </REQ1_DAT2>
...
</COMMAND_DATA>

or

<COMMAND>REQUEST2</COMMAND>
<COMMAND_DATA>
<REQ2_DAT1> something </REQ2_DAT1>
<REQ2_DAT2> something </REQ2_DAT2>
<REQ2_DAT3> something </REQ2_DAT3>
...
</COMMAND_DATA>

or

<COMMAND>REQUEST3</COMMAND>
<COMMAND_DATA>
<REQ3_DAT1> something </REQ3_DAT1>

...
</COMMAND_DATA>


If you want the tail end of a sequence of siblings to
depend on the beginning, there is a very easy way to do it.
Why not write

<REQUEST1>
<REQ1_DAT1> something </REQ1_DAT1>
<REQ1_DAT2> something </REQ1_DAT2>
...
</REQUEST1>

or

<REQUEST2>
<REQ2_DAT1> something </REQ2_DAT1>
<REQ2_DAT2> something </REQ2_DAT2>
<REQ2_DAT3> something </REQ2_DAT3>
</REQUEST2>

etc.?

Since you appear to have an exhaustive list of commands,
this would appear fairly straightforward.

Alternatively, if your collaborators insist that they
must have the same wrapper 'COMMAND_DATA' around what
are necessarily very different kinds of contents, you
could write

<COMMAND_DATA xsi:type="REQUEST1">
<REQ1_DAT1> something </REQ1_DAT1>
<REQ1_DAT2> something </REQ1_DAT2>
...
</COMMAND_DATA>

or

<COMMAND_DATA xsi:type="REQUEST2">
<REQ2_DAT1> something </REQ2_DAT1>
<REQ2_DAT2> something </REQ2_DAT2>
<REQ2_DAT3> something </REQ2_DAT3>
...
</COMMAND_DATA>

and define types REQUEST1, REQUEST2, etc. as restrictions
of a more generic COMMAND_DATA type.

If you are stuck with a vocabulary designed to fight your
validation tools, however, and really cannot change it, all
I can say is you have my sympathy.

-C. M. Sperberg-McQueen
World Wide Web Consortium
Jul 20 '05 #4

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

Similar topics

198
by: Sridhar R | last post by:
>From technical point of view, I could not understand the the reasoning behind using Java in major companies. Sure that Python, is used in some, but still Java is considered as a sure-job...
0
by: GB | last post by:
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?...
3
by: Kimmo J?rvikangas | last post by:
Dear XML (Schema) experts, As an example I have the following schema: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"...
4
by: Dennis Vroegop | last post by:
Hi there! I have the following XSD (Well, this is not the real one, but the concept is the same....) <?xml version="1.0" encoding="UTF-8"?> <xs:schema...
2
by: Matthew | last post by:
I have implemented the xmlSchemaCollection object to cache commonly used schemas, as follows: =============================================================================== public void...
4
by: Sergey Poberezovskiy | last post by:
Hi, As part of my schema I need to ensure that at least one of two fields have values. I defined my schema as follows: .... <xs:choice> <xs:element ref="el1"/> <xs:element ref="el2"/>...
23
by: SenthilVel | last post by:
Hi Can any one let me know the websites/Pdf for learning Aggragation in C#?? Thanks Senthil
0
by: =?Utf-8?B?RGFtaWFu?= | last post by:
(This is using .net version 2.0.50727 and system.xml 2.0.50727.42) I am getting an error when serializing using classes generated by xsd.exe. The error is of the type "The Type <typewas not...
0
by: Peter Larsen | last post by:
Is this really a valid schema design? <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="root">...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.