[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: How to do a choice on aggregation with w3C XML schema


xml choice
Hi Sony,

I'm still a bit new to schemas, so I might be just a little off here, but I think I see what you are trying to do.  I don't think you will be able to do it completely with xml schemas.

For the schema part, you could probably take it down to something like this

<xs:simpleType name="reqTyp">
  <xs:restriction base="xs:string">
    <xs:pattern value="REQUEST1"/>
    <xs:pattern value="REQUEST2"/>
    <xs:pattern value="REQUEST3"/>
  </xs:restriction>
</xs:simpleType>


<xs:complexType name="reqDatTyp">
  <xs:sequence>
    <xs:element name="REQ1_DAT1" minOccurs="0" maxOccurs="1"/>
    <xs:element name="REQ1_DAT2" minOccurs="0" maxOccurs="1"/>
    ...
    <xs:element name="REQ2_DAT1" minOccurs="0" maxOccurs="1"/>
    <xs:element name="REQ2_DAT2" minOccurs="0" maxOccurs="1"/>
    <xs:element name="REQ2_DAT3" minOccurs="0" maxOccurs="1"/>
    ...
    <xs:element name="REQ3_DAT1" minOccurs="0" maxOccurs="1"/>
    ...
  </xs:sequence>
</xs:sequence>


Notice that this does not restrict the data to a choice between one of the different types (I know that is something you need here).  If you were going to do that with xml schemas, I don't think you could make it a choice of sequences, but rather of elements with those sequences in them (it doesn't look like that will fit your intended schema, however).  In any case, it still wouldn't be able to validate that the right element was used in relation to the value in the "COMMAND" tag.

Since you are requiring a restriction to specific elements based on a value in another element, you would likely have to use XSLT to break that information out.  You could use an XPath expression to find the offending code and return an error if it is found.  Mr. Costello has an excellent site that discusses much of this information http://www.xfront.com .

Here is one document that contains information that discusses this.  Take a look at page 7.
http://www.xfront.com/ExtendingSchemas.pdf


At the moment, I don't have an example to give you, hopefully someone here will come up with something.  In any case, I hope I am getting you on the right track.

If someone else on the list knows something I don't, in regards to this, please let me know.  This is an issue that concerns me as well.

Chris Strolia-Davis
Database Specialist
Contractor - CDO Technologies Inc.


-----Original Message-----
From: santony@b... [mailto:santony@b...]
Sent: Thursday, December 18, 2003 12:34 AM
To: xml-dev@l...
Subject:  How to do a choice on aggregation with w3C 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



-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
initiative of OASIS <http://www.oasis-open.org>

The list archives are at http://lists.xml.org/archives/xml-dev/

To subscribe or unsubscribe from this list use the subscription
manager: <http://lists.xml.org/ob/adm.pl>

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.