Schema attribute restriction

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nicolaspujol@yahoo.com

    Schema attribute restriction

    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:complexTy pe name="customer" >
    <xs:sequence>
    <xs:element name="firstname " type="xs:string "/>
    </xs:sequence>
    <xs:attribute name="life" use="optional">
    <xs:simpleTyp e>
    <xs:restricti on base="xs:NMTOKE N">
    <xs:enumerati on value="session"/>
    <xs:enumerati on value="request"/>
    <xs:enumerati on value="context"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>
    </xs:complexType>

    I would like "Norwegian_cust omer" 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:complexTy pe name="Norwegian _customer">
    <xs:complexCont ent>
    <xs:restricti on base="pf:custom er">
    <xs:sequence>
    <xs:element name="firstname " type="xs:string "/>
    </xs:sequence>
    <xs:attribute name="life" use="optional">
    <xs:simpleTyp e>
    <xs:restricti on base="xs:NMTOKE N">
    <xs:enumerati on value="session"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>
    </xs:restriction>
    </xs:complexConte nt>
    </xs:complexType>


    Thanks in advance

  • Priscilla Walmsley

    #2
    Re: Schema attribute restriction

    Hi,

    In order for this to work, the simple type of "life" in
    Norwegian_custo mer 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:complexTy pe name="customer" >
    <xs:sequence>
    <xs:element name="firstname " type="xs:string "/>
    </xs:sequence>
    <xs:attribute name="life" use="optional" type="lifetype"/>
    </xs:complexType>

    <xs:simpleTyp e name="lifetype" >
    <xs:restricti on base="xs:NMTOKE N">
    <xs:enumerati on value="session"/>
    <xs:enumerati on value="request"/>
    <xs:enumerati on value="context"/>
    </xs:restriction>
    </xs:simpleType>

    <xs:complexTy pe name="Norwegian _customer">
    <xs:complexCont ent>
    <xs:restricti on base="pf:custom er">
    <xs:sequence>
    <xs:element name="firstname " type="xs:string "/>
    </xs:sequence>
    <xs:attribute name="life" use="optional">
    <xs:simpleTyp e>
    <xs:restricti on base="lifetype" >
    <xs:enumerati on value="session"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>
    </xs:restriction>
    </xs:complexConte nt>
    </xs:complexType>

    Hope that helps,
    Priscilla
    ----------------------------------
    Priscilla Walmsley
    Author, Definitive XML Schema

    ----------------------------------

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!

    Comment

    • NP

      #3
      Re: Schema attribute restriction

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

      Thanks


      Priscilla Walmsley wrote:[color=blue]
      > Hi,
      >
      > In order for this to work, the simple type of "life" in
      > Norwegian_custo mer 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:complexTy pe name="customer" >
      > <xs:sequence>
      > <xs:element name="firstname " type="xs:string "/>
      > </xs:sequence>
      > <xs:attribute name="life" use="optional" type="lifetype"/>
      > </xs:complexType>
      >
      > <xs:simpleTyp e name="lifetype" >
      > <xs:restricti on base="xs:NMTOKE N">
      > <xs:enumerati on value="session"/>
      > <xs:enumerati on value="request"/>
      > <xs:enumerati on value="context"/>
      > </xs:restriction>
      > </xs:simpleType>
      >
      > <xs:complexTy pe name="Norwegian _customer">
      > <xs:complexCont ent>
      > <xs:restricti on base="pf:custom er">
      > <xs:sequence>
      > <xs:element name="firstname " type="xs:string "/>
      > </xs:sequence>
      > <xs:attribute name="life" use="optional">
      > <xs:simpleTyp e>
      > <xs:restricti on base="lifetype" >
      > <xs:enumerati on value="session"/>
      > </xs:restriction>
      > </xs:simpleType>
      > </xs:attribute>
      > </xs:restriction>
      > </xs:complexConte nt>
      > </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![/color]

      Comment

      • Priscilla Walmsley

        #4
        Re: Schema attribute restriction

        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

        ----------------------------------

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        Working...