XML schema extension question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Antony

    #1

    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:simpleTy pe name="currencyS ymbol">
    <xsd:restrictio n base="xsd:strin g">
    <xsd:enumeratio n value="UKL"/>
    <xsd:enumeratio n value="USD"/>
    <xsd:enumeratio n value="AUD"/>
    </xsd:restriction >
    </xsd:simpleType>

    <xsd:element name="customers ">
    <xsd:complexTyp e>

    <xsd:sequence >

    <xsd:element name="companySh areDetails"
    minOccurs="1" maxOccurs="unbo unded"[color=blue]
    >[/color]
    <xsd:complexTyp e>
    <xsd:sequence >
    <xsd:element name="companyCo de" type="xsd:strin g"/>
    <xsd:element name="symbol" type="currencyS ymbol"/>
    <xsd:element name="currency" type="xsd:strin g"
    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>

    <companyShareDe tails>
    <companyCode>UP C2331</companyCode>
    <symbol>USD</symbol>
    </companyShareDet ails>

    <companyShareDe tails>
    <companyCode>GE C1045</companyCode>
    <symbol>UKL</symbol>
    </companyShareDet ails>


    <companyShareDe tails>
    <companyCode>GE C1045</companyCode>
    <symbol>UKL</symbol>
    <currency>UKL </currency>
    </companyShareDet ails>

    <companyShareDe tails>
    <companyCode>BA E4491</companyCode>
    <symbol>UKL</symbol>
    <currency>GBP </currency>
    </companyShareDet ails>

    <companyShareDe tails>
    <companyCode>CC M9002</companyCode>
    <symbol>UKL</symbol>
    <currency>STG </currency>
    </companyShareDet ails>

    </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><currenc y>GBP</currency> is valid.
    <symbol>UKL</symbol><currenc y>UKL</currency> is valid.
    <symbol>UKL</symbol><currenc y>STG</currency> is valid.
    <symbol>UKL</symbol> is valid.
    <symbol>UKL</symbol><currenc y>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
Working...