468,140 Members | 1,406 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,140 developers. It's quick & easy.

XML schema extension question

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
Jul 20 '05 #1
0 4751

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Gregg Williams | last post: by
2 posts views Thread by inquirydog | last post: by
3 posts views Thread by Kanchana D S | last post: by
1 post views Thread by billa1972 | last post: by
4 posts views Thread by olivier.scalbert | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.