Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > How to do a choice on aggregation with XML schema

Reply
Thread Tools

How to do a choice on aggregation with XML schema

 
 
Sony Antony
Guest
Posts: n/a
 
      12-18-2003
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">
<xsattern value="REQUEST1"/>
</xs:restriction>
</xs:simpleType>

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

<xs:simpleType name="req1Typ">
<xs:restriction base="xs:string">
<xsattern 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
 
Reply With Quote
 
 
 
 
Sony Antony
Guest
Posts: n/a
 
      12-18-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Sony Antony) wrote in message news:<(E-Mail Removed). 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">
> <xsattern value="REQUEST1"/>
> </xs:restriction>
> </xs:simpleType>
>
> <xs:simpleType name="req2Typ">
> <xs:restriction base="xs:string">
> <xsattern value="REQUEST2"/>
> </xs:restriction>
> </xs:simpleType>
>
> <xs:simpleType name="req1Typ">
> <xs:restriction base="xs:string">
> <xsattern 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

 
Reply With Quote
 
 
 
 
Finnbarr P. Murphy
Guest
Posts: n/a
 
      12-19-2003
(E-Mail Removed) (Sony Antony) wrote in message news:<(E-Mail Removed). 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
 
Reply With Quote
 
C. M. Sperberg-McQueen
Guest
Posts: n/a
 
      12-19-2003
(E-Mail Removed) (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
 
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