Schema attribute restriction

Discussion in 'XML' started by nicolaspujol@yahoo.com, Jan 23, 2005.

  1. Guest

    Hi, wondering if anybody could help me figure how to. in schema,
    restrict the list of tokens I may have as an attribute value. For
    example

    <xs:complexType name="customer">
    <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    </xs:sequence>
    <xs:attribute name="life" use="optional">
    <xs:simpleType>
    <xs:restriction base="xs:NMTOKEN">
    <xs:enumeration value="session"/>
    <xs:enumeration value="request"/>
    <xs:enumeration value="context"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>
    </xs:complexType>

    I would like "Norwegian_customer" to extend from customer but to allow
    for the "life" attribute only the "session" value. This is what I am
    doing so far but is not correct.

    <xs:complexType name="Norwegian_customer">
    <xs:complexContent>
    <xs:restriction base="pf:customer">
    <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    </xs:sequence>
    <xs:attribute name="life" use="optional">
    <xs:simpleType>
    <xs:restriction base="xs:NMTOKEN">
    <xs:enumeration value="session"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>
    </xs:restriction>
    </xs:complexContent>
    </xs:complexType>


    Thanks in advance
     
    , Jan 23, 2005
    #1
    1. Advertising

  2. Hi,

    In order for this to work, the simple type of "life" in
    Norwegian_customer has to explicitly say it is a restriction of the
    simple type of "life" in customer. For this, you need to use a named
    simple type, like this:

    <xs:complexType name="customer">
    <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    </xs:sequence>
    <xs:attribute name="life" use="optional" type="lifetype"/>
    </xs:complexType>

    <xs:simpleType name="lifetype">
    <xs:restriction base="xs:NMTOKEN">
    <xs:enumeration value="session"/>
    <xs:enumeration value="request"/>
    <xs:enumeration value="context"/>
    </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="Norwegian_customer">
    <xs:complexContent>
    <xs:restriction base="pf:customer">
    <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    </xs:sequence>
    <xs:attribute name="life" use="optional">
    <xs:simpleType>
    <xs:restriction base="lifetype">
    <xs:enumeration value="session"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>
    </xs:restriction>
    </xs:complexContent>
    </xs:complexType>

    Hope that helps,
    Priscilla
    ----------------------------------
    Priscilla Walmsley
    Author, Definitive XML Schema
    http://www.datypic.com
    ----------------------------------

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Priscilla Walmsley, Jan 24, 2005
    #2
    1. Advertising

  3. NP Guest

    Thanks , though XMLSpy allows it , it does not seem able to validate it
    using MSXML.

    Thanks


    Priscilla Walmsley wrote:
    > Hi,
    >
    > In order for this to work, the simple type of "life" in
    > Norwegian_customer has to explicitly say it is a restriction of the
    > simple type of "life" in customer. For this, you need to use a named
    > simple type, like this:
    >
    > <xs:complexType name="customer">
    > <xs:sequence>
    > <xs:element name="firstname" type="xs:string"/>
    > </xs:sequence>
    > <xs:attribute name="life" use="optional" type="lifetype"/>
    > </xs:complexType>
    >
    > <xs:simpleType name="lifetype">
    > <xs:restriction base="xs:NMTOKEN">
    > <xs:enumeration value="session"/>
    > <xs:enumeration value="request"/>
    > <xs:enumeration value="context"/>
    > </xs:restriction>
    > </xs:simpleType>
    >
    > <xs:complexType name="Norwegian_customer">
    > <xs:complexContent>
    > <xs:restriction base="pf:customer">
    > <xs:sequence>
    > <xs:element name="firstname" type="xs:string"/>
    > </xs:sequence>
    > <xs:attribute name="life" use="optional">
    > <xs:simpleType>
    > <xs:restriction base="lifetype">
    > <xs:enumeration value="session"/>
    > </xs:restriction>
    > </xs:simpleType>
    > </xs:attribute>
    > </xs:restriction>
    > </xs:complexContent>
    > </xs:complexType>
    >
    > Hope that helps,
    > Priscilla
    > ----------------------------------
    > Priscilla Walmsley
    > Author, Definitive XML Schema
    > http://www.datypic.com
    > ----------------------------------
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    NP, Jan 24, 2005
    #3
  4. What error message are you getting? Maybe if you post your whole schema
    and instance it will be more obvious what is wrong.

    Priscilla

    ----------------------------------
    Priscilla Walmsley
    Author, Definitive XML Schema
    http://www.datypic.com
    ----------------------------------

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Priscilla Walmsley, Jan 25, 2005
    #4
    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. Markus
    Replies:
    1
    Views:
    1,641
    Markus
    Nov 23, 2005
  2. Andy Howden
    Replies:
    0
    Views:
    515
    Andy Howden
    Oct 20, 2003
  3. Andrew L
    Replies:
    0
    Views:
    927
    Andrew L
    Jan 28, 2004
  4. Replies:
    1
    Views:
    458
    Stan Kitsis [MSFT]
    Dec 29, 2004
  5. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,314
    Stanimir Stamenkov
    Apr 25, 2005
Loading...

Share This Page