An XML Scheme question - How to express a tag in XSD

Hi.

I'm trying to write an XSD to a certain XML (the CD_CATALOG famous example..), which has this kind of tag, which can appear in two formats:

<PRICE value="34.9"/>

or

<PRICE>45.45</PRICE>

the following expression just won't do, for it won't allow the first format.

<xs:element name="PRICE">

<xs:complexType>

<xs:simpleContent>

<xs:extension base="xs:decimal">

<xs:attribute name="value" type="xs:decimal"/>

</xs:extension>

</xs:simpleContent>

</xs:complexType>

</xs:element>

Please Please tell me if you have any Idea..

Guy

[703 byte] By [Linksmana] at [2007-9-23]
# 1

Could you not add a xs:choice element, like this:

<xs:complexType>

<xs:choice>

<xs:element name = 'price'>

<xs:complexType>

<xs:attribute name = 'value' type = 'xs:decimal'/>

</xs:complexType>

</xs:element>

<xs:element name = 'price'>

<xs:simpleType>

<xs:restriction base = 'xs:decimal'/>

</xs:simpleType>

</xs:element>

</xs:choice>

</xs:complexType>

y0241695@uea.ac.uka at 2007-7-10 > top of java,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Thanks for your answer but it won't do..

Defining two elements with the same name produces a name conflict.

The solution I found is to set the value type to STRING instead of DECIMAL.

Apparently, a STRING can be empty, but a decimal value cannot (it sould have some value)

Tnx, anyway,

Guy

Linksmana at 2007-7-10 > top of java,Enterprise & Remote Computing,Enterprise Technologies...