Re: [xml] General XML Schema question



Now I would like to create a rule which says for example if the user
chose the enumerator MY_SPECIAL_TYPE_STRING than the type of "Value" has
to be "xsd:string". If the enumerator was MY_SPECIAL_TYPE_INTEGER than
the type of "Value" should be "xsd:integer". And maybe if this is even
possible create my own type for "Value".

Better places to ask this sort of question are xmlschema-dev w3 org, xml-dev lists xml org and the comp.text.xml newsgroup. You may have to do a bit of detective work to find out how to subscribe to these.

To answer your question, you can't use XML schema to do this. (I'm not sure even if RelaxNG can do this.)

A more schema friendly way of do this would be to do:

<xsd:complexType>
 <xsd:choice>
   <xsd:element name="MY_SPECIAL_TYPE_STRING" type="xsd:string"/>
   <xsd:element name="MY_SPECIAL_TYPE_INTEGER" type="xsd:int"/>
   <xsd:element name="MY_SPECIAL_TYPE_OF_WHATEVER" type="???"/>
 </xsd:choice>
</xsd:complexType>

Your XML instance then looks like:

<MY_SPECIAL_TYPE_STRING>MyString</MY_SPECIAL_TYPE_STRING>

XSD1.1 is looking at a feature where an attribute (but not an element) can specify constraints on the type of a child element. This work is a way off yet, so I wouldn't wait for it!

HTH,

Pete Cordell
Codalogic
Visit http://www.codalogic.com/lmx/
for XML Schema to C++ data binding

----- Original Message ----- From: "Stefan Schulze Frielinghaus" <stefan seekline net>
To: <xml gnome org>
Sent: Friday, December 21, 2007 9:08 AM
Subject: [xml] General XML Schema question


Hi,

I'm not aware of any other XML mailinglist, forum or whatever so I would
like to post my question here in the hope that someone else has an idea.

This is the scenario, an enumerator which should specify of which type a
special subset of my XML file is.

<xsd:simpleType name="myType">
 <xsd:restriction base="xsd:string">
   <xsd:enumeration value="MY_SPECIAL_TYPE_STRING"/>
   <xsd:enumeration value="MY_SPECIAL_TYPE_INTEGER"/>
   <xsd:enumeration value="MY_SPECIAL_TYPE_OF_WHATEVER"/>
 </xsd:restriction>
</xsd:simpleType>

and a complexType which holds the actual enumerator type and the value
itself.

<xsd:complexType>
 <xsd:sequence>
   <xsd:element name="Type" type="myType"/>
   <xsd:element name="Value" type="xsd:string"/>
 </xsd:sequence>
</xsd:complexType>

Now I would like to create a rule which says for example if the user
chose the enumerator MY_SPECIAL_TYPE_STRING than the type of "Value" has
to be "xsd:string". If the enumerator was MY_SPECIAL_TYPE_INTEGER than
the type of "Value" should be "xsd:integer". And maybe if this is even
possible create my own type for "Value".

I'm not sure if this is even possible with XML Schema. I guess I have to
do it programmatically but I would like to hear a second opinion.

Best regards
Stefan





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]