xsd restriction

Discussion in 'XML' started by Ed Slen, Jun 25, 2003.

  1. Ed Slen

    Ed Slen Guest

    Hi, Guys!
    Have a question about xsd restriction:

    I am having an element "state" and it could be US state (Which is
    easy) or Canadian postal code which is easy too (both rules are
    working separately), but I am having difficulties combining this two
    rules together.
    Here is what I have tried:

    <xsd:simpleType name="StateType">
    <xsd:union>
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d" />
    </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType>
    <xsd:restriction base="b:usState">
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:union>
    </xsd:simpleType>


    <xsd:simpleType name="usState">
    <xsd:restriction base="xsd:NMTOKEN">
    <xsd:enumeration value="AL"/>
    <!—and all of other states up to: à
    <xsd:enumeration value="WY"/>
    </xsd:restriction>
    </xsd:simpleType>

    this gives enumeration error if I use Canadian postal code.

    Please, help!
    What am I doing wrong?

    Thanks in advance!
     
    Ed Slen, Jun 25, 2003
    #1
    1. Advertising

  2. Ed Slen

    Derek Harmon Guest

    "Ed Slen" <> wrote in message news:...
    > <xsd:simpleType name="StateType">

    : :
    > <xsd:restriction base="b:usState">

    : :
    > <xsd:simpleType name="usState">

    : :
    > this gives enumeration error if I use Canadian postal code.


    This works for me, assuming the prefix b is defined as your targetNamespace.

    Your XML Schema snippet did not include an element declaration, I'd just check
    for what might be an obvious snag:

    <xsd:element name="location" type="b:StateType" /> <!-- OK -->
    <xsd:element name="location" type="b:usState" /> <!-- Not the Union type: Bug -->

    You would get an enumeration error if the element where the Canadian postal
    code appears is making reference to the b:usState type instead of the union
    type, b:StateType.


    Derek Harmon
     
    Derek Harmon, Jun 25, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cat
    Replies:
    3
    Views:
    2,701
    Henry S. Thompson
    Jun 25, 2004
  2. Lars Geldner

    [XSD] derivation by restriction

    Lars Geldner, Dec 27, 2004, in forum: XML
    Replies:
    4
    Views:
    630
    Henry S. Thompson
    Jan 7, 2005
  3. SP

    XSD restriction

    SP, Sep 26, 2005, in forum: XML
    Replies:
    0
    Views:
    469
  4. Replies:
    1
    Views:
    452
    Priscilla Walmsley
    Jun 14, 2006
  5. Replies:
    7
    Views:
    723
Loading...

Share This Page