- From: <noah_mendelsohn@us.ibm.com>
- Date: Fri, 19 Dec 2003 10:44:07 -0500
- To: <santony@bellsouth.net>
- Cc: xmlschema-dev@w3.org
Two answers: 1) This is a question that gets asked in one form or another every few weeks and the simple answer is "no, not in this version of XML schema". You're looking for what we call a value-based co-occurrence constraint, because the inclusion of certain elements is dependent on the value of another. We are looking at various co-occurrence mechanisms for future releases, but value-based are not necessarily the highest priority. More likely is: "either this attribute or that element". 2) Having said that, you are not really leveraging the power of XML markup in your instance documents. If you would do something like this, your messages would be clearer and more self-describing, and you would have an easy time using XML schema for them. <COMMAND> <REQUEST1> <REQ1_DAT1> something </REQ1_DAT1> <REQ1_DAT2> something </REQ1_DAT2> </REQUEST1> </COMMAND_DATA> or <COMMAND> <REQUEST2> <REQ2_DAT1> something </REQ2_DAT1> <REQ2_DAT2> something </REQ2_DAT2> <REQ2_DAT3> something </REQ2_DAT3> </REQUEST2> </COMMAND_DATA> If your commands are being invented by different organizations, you could apply namespaces to minimize the chance that their command names and argument names collide <cmd:COMMAND xmlns:cmd="cmdUri"> <r1:REQUEST1 xmlns:r1="r1Uri"> <r1:REQ1_DAT1> something </r1:REQ1_DAT1> <r1:REQ1_DAT2> something </r1:REQ1_DAT2> </REQUEST1> </cmd:COMMAND_DATA> or <cmd:COMMAND xmlns:cmd="cmdUri"> <r2:REQUEST2 xmlns:r2="r2Uri"> <r2:REQ2_DAT1> something </r2:REQ2_DAT1> <r2:REQ2_DAT2> something </r2:REQ2_DAT2> <r2:REQ2_DAT3> something </r2:REQ2_DAT3> </r2:REQUEST2> </cmd:COMMAND_DATA> Now if two of your organizations invent the name "request2", they will presumably use different namespaces for them. Even better, each organization can maintain its own schema document for the namespace of the commands that it controls. Import them all, or use your choice of strict or lax wildcard validation of the COMMAND element to validate the overall command message and its arguments. I'm not sure whether you can change your format at this point, but the above looks like much better use of XML in a whole bunch of ways, and I think it will work just fine with XML schema. Hope this helps. -------------------------------------- Noah Mendelsohn IBM Corporation One Rogers Street Cambridge, MA 02142 1-617-693-4036 -------------------------------------- <santony@bellsouth.net> Sent by: xmlschema-dev-request@w3.org 12/17/2003 11:59 PM To: <xmlschema-dev@w3.org> cc: (bcc: Noah Mendelsohn/Cambridge/IBM) Subject: 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
Received on Friday, 19 December 2003 10:52:30 UTC