xsd restriction

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

    #1

    xsd restriction

    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:simpleTy pe name="StateType ">
    <xsd:union>
    <xsd:simpleType >
    <xsd:restrictio n base="xsd:strin g">
    <xsd:pattern value="[a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d" />
    </xsd:restriction >
    </xsd:simpleType>
    <xsd:simpleType >
    <xsd:restrictio n base="b:usState ">
    </xsd:restriction >
    </xsd:simpleType>
    </xsd:union>
    </xsd:simpleType>


    <xsd:simpleTy pe name="usState">
    <xsd:restrictio n base="xsd:NMTOK EN">
    <xsd:enumeratio n value="AL"/>
    <!—and all of other states up to: à
    <xsd:enumeratio n 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!
  • Derek Harmon

    #2
    Re: xsd restriction

    "Ed Slen" <edsuslen@yahoo .com> wrote in message news:5325e256.0 306251204.36dd5 93f@posting.goo gle.com...[color=blue]
    > <xsd:simpleTy pe name="StateType ">[/color]
    : :[color=blue]
    > <xsd:restrictio n base="b:usState ">[/color]
    : :[color=blue]
    > <xsd:simpleTy pe name="usState">[/color]
    : :[color=blue]
    > this gives enumeration error if I use Canadian postal code.[/color]

    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:StateTy pe" /> <!-- 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


    Comment

    Working...