473,796 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>REQUES T1</COMMAND>
<COMMAND_DATA >
<REQ1_DAT1> something </REQ1_DAT1>
<REQ1_DAT2> something </REQ1_DAT2>
....
</COMMAND_DATA>

or

<COMMAND>REQUES T2</COMMAND>
<COMMAND_DATA >
<REQ2_DAT1> something </REQ2_DAT1>
<REQ2_DAT2> something </REQ2_DAT2>
<REQ2_DAT3> something </REQ2_DAT3>
....
</COMMAND_DATA>

or

<COMMAND>REQUES T3</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:simpleTyp e name="req1Typ">
<xs:restricti on base="xs:string ">
<xs:pattern value="REQUEST1 "/>
</xs:restriction>
</xs:simpleType>

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

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

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

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

<xs:complexTy pe name req3DatTyp>
<xs:sequence>
<xs:element name="REQ3_DAT1 "/>
...
<xs:sequence>
</xs:complexType>
<xs:complexTy pe name="choice_on _aggregation" >
<xs:choice>
<xs:sequence>
<xs:element name="COMMAND" type="req1Typ">
<xs:element name="COMMAND_D ATA" type="req1DatTy p">
</xs:sequence>
<xs:sequence>
<xs:element name="COMMAND" type="req2Typ">
<xs:element name="COMMAND_D ATA" type="req1DatTy p">
</xs:sequence>
<xs:sequence>
<xs:element name="COMMAND" type="req3Typ">
<xs:element name="COMMAND_D ATA" type="req1DatTy p">
</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.c om/wfaif":COMMAND and
"http://www.bellsouth.c om/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 1722
so********@hotm ail.com (Sony Antony) wrote in message news:<3e******* *************** ****@posting.go ogle.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>REQUES T1</COMMAND>
<COMMAND_DATA >
<REQ1_DAT1> something </REQ1_DAT1>
<REQ1_DAT2> something </REQ1_DAT2>
...
</COMMAND_DATA>

or

<COMMAND>REQUES T2</COMMAND>
<COMMAND_DATA >
<REQ2_DAT1> something </REQ2_DAT1>
<REQ2_DAT2> something </REQ2_DAT2>
<REQ2_DAT3> something </REQ2_DAT3>
...
</COMMAND_DATA>

or

<COMMAND>REQUES T3</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:simpleTyp e name="req1Typ">
<xs:restricti on base="xs:string ">
<xs:pattern value="REQUEST1 "/>
</xs:restriction>
</xs:simpleType>

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

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

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

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

<xs:complexTy pe name req3DatTyp>
<xs:sequence>
<xs:element name="REQ3_DAT1 "/>
...
<xs:sequence>
</xs:complexType>
<xs:complexTy pe name="choice_on _aggregation" >
<xs:choice>
<xs:sequence>
<xs:element name="COMMAND" type="req1Typ">
<xs:element name="COMMAND_D ATA" type="req1DatTy p">
</xs:sequence>
<xs:sequence>
<xs:element name="COMMAND" type="req2Typ">
<xs:element name="COMMAND_D ATA" type="req1DatTy p">
</xs:sequence>
<xs:sequence>
<xs:element name="COMMAND" type="req3Typ">
<xs:element name="COMMAND_D ATA" type="req1DatTy p">
</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.c om/wfaif":COMMAND and
"http://www.bellsouth.c om/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********@hotm ail.com (Sony Antony) wrote in message news:<3e******* *************** ****@posting.go ogle.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********@hotm ail.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>REQUES T1</COMMAND>
<COMMAND_DATA >
<REQ1_DAT1> something </REQ1_DAT1>
<REQ1_DAT2> something </REQ1_DAT2>
...
</COMMAND_DATA>

or

<COMMAND>REQUES T2</COMMAND>
<COMMAND_DATA >
<REQ2_DAT1> something </REQ2_DAT1>
<REQ2_DAT2> something </REQ2_DAT2>
<REQ2_DAT3> something </REQ2_DAT3>
...
</COMMAND_DATA>

or

<COMMAND>REQUES T3</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="REQUE ST1">
<REQ1_DAT1> something </REQ1_DAT1>
<REQ1_DAT2> something </REQ1_DAT2>
...
</COMMAND_DATA>

or

<COMMAND_DATA xsi:type="REQUE ST2">
<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
7734
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 language. After being a python programmer for long time, I consider it painful to learn/use Java now (well, like many I will be forced to do that in my job). What makes such companies to choose Java over dynamic, productive languages like Python? ...
0
1605
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? 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?
3
4564
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" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="ROOT_ELEMENT"> <xs:complexType> <xs:choice>
4
9000
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 xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:complexType name="DataItemType"> <xs:choice>
2
2374
by: Matthew | last post by:
I have implemented the xmlSchemaCollection object to cache commonly used schemas, as follows: =============================================================================== public void SchemaValidate(XmlDocument xmlDoc, string schemaURI, string urnNamespace) {
4
1731
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"/> <xs:sequence> <xs:element ref="el1"/>
23
2129
by: SenthilVel | last post by:
Hi Can any one let me know the websites/Pdf for learning Aggragation in C#?? Thanks Senthil
0
2145
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 expected. Use the XmlInclude or SoapInclude etc" This error is appearing sprodically, with no obvious pattern. When it occurs, it happens every time we run the code, however changes to our code in creating the objects before they are serialized...
0
2842
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"> <xs:complexType> <xs:sequence> <xs:choice> <xs:element name="e1" minOccurs="0" />
0
9529
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10457
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10231
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7550
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4119
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.