Schema attribute restriction

N

nicolaspujol

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
 
P

Priscilla Walmsley

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
 
N

NP

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

Thanks
 
P

Priscilla Walmsley

What error message are you getting? Maybe if you post your whole schema
and instance it will be more obvious what is wrong.

Priscilla
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top