XML schema extension question

A

Antony

Hi there, firstly thank you for thinking about this problem of mine.
This is a long message because I want to put all the facts (the XML
and the schema) to try to get a solution from you helpful readers of
the newsgroup.

Here is my problem. I have defined the following XML schema.

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:simpleType name="currencySymbol">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="UKL"/>
<xsd:enumeration value="USD"/>
<xsd:enumeration value="AUD"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:element name="customers">
<xsd:complexType>

<xsd:sequence>

<xsd:element name="companyShareDetails"
minOccurs="1" maxOccurs="unbounded"<xsd:complexType>
<xsd:sequence>
<xsd:element name="companyCode" type="xsd:string"/>
<xsd:element name="symbol" type="currencySymbol"/>
<xsd:element name="currency" type="xsd:string"
minOccurs="0" maxOccurs="1"
/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

</xsd:sequence>

</xsd:complexType>
</xsd:element>

</xsd:schema>


Here is an example of the type of XML validated by this schema. This
XML is valid according to this schema.

<customers>

<companyShareDetails>
<companyCode>UPC2331</companyCode>
<symbol>USD</symbol>
</companyShareDetails>

<companyShareDetails>
<companyCode>GEC1045</companyCode>
<symbol>UKL</symbol>
</companyShareDetails>


<companyShareDetails>
<companyCode>GEC1045</companyCode>
<symbol>UKL</symbol>
<currency>UKL</currency>
</companyShareDetails>

<companyShareDetails>
<companyCode>BAE4491</companyCode>
<symbol>UKL</symbol>
<currency>GBP</currency>
</companyShareDetails>

<companyShareDetails>
<companyCode>CCM9002</companyCode>
<symbol>UKL</symbol>
<currency>STG</currency>
</companyShareDetails>

</customers>


But I would like it to be validated so that when <currency> is
present, then the element can only be certain values. Furthermore the
values it can be will vary for each <symbol>. The allowed values will
be different for every currency because there is often more than one
valid currency symbol for a currency (including historical data,
Germany is now Euro but of course used to also be the Mark), and the
UK has lots of currency symbols because it just does.

ie <symbol> <currency>
UKL 'UKL' United Kingdom Pounds
UKL 'STG' United Kingdom Pounds (Sterling)
UKL 'GBP' United Kingdom Pounds

USD 'USD' United States Dollar

DEM 'DEM' Deutche Mark
DEM 'EUR' Euro

JPY 'JPY' Japanese Yen
JPY 'YEN' Japanese Yen

So <symbol>UKL</symbol><currency>GBP</currency> is valid.
<symbol>UKL</symbol><currency>UKL</currency> is valid.
<symbol>UKL</symbol><currency>STG</currency> is valid.
<symbol>UKL</symbol> is valid.
<symbol>UKL</symbol><currency>EUR</currency> IS NOT VALID.

My question is can my XML schema be extended so that when <symbol> is
present, it can only be allowed predefined values. I want the solution
to be elegant, I do not want to have to create a 'Facet' for each
currency <symbol>.

Thank you
Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top