restrictions for attributes

R

ruthless

hello.

I've got a problem - can I do any restrictions for my attributes?

I found how to restrict elements and was trying to use them with my
attributes

e.g. <person sex="F"> sex can be anly F and M

i've got sth like this:

<xs:complexType name="person-type">
[...]
<xs:attribute name="sex">
<xs:restriction base="xs:string">
<xs:pattern value="F|M"/>
</xs:restriction>
</xs:attribute>
</xs:complexType>

when I valid it using: http://www.w3.org/2001/03/webdata/xsv i recieve info:

* The schema(s) used for schema-validation had no errors

so my scheme is correct or not?
I recieve errors while i'm validating xml + xsd, xsd itself is valid(see
above)

xml is correct i have only change my xsd file with the sex attribute
without sex restrictions it was OK

thnx in advance
 
M

Martin Honnen

I've got a problem - can I do any restrictions for my attributes?

I found how to restrict elements and was trying to use them with my
attributes

e.g. <person sex="F"> sex can be anly F and M

i've got sth like this:

<xs:complexType name="person-type">
[...]
<xs:attribute name="sex">
<xs:restriction base="xs:string">
<xs:pattern value="F|M"/>
</xs:restriction>
</xs:attribute>
</xs:complexType>

when I valid it using: http://www.w3.org/2001/03/webdata/xsv i recieve info:

* The schema(s) used for schema-validation had no errors

so my scheme is correct or not?
I recieve errors while i'm validating xml + xsd, xsd itself is valid(see
above)

xml is correct i have only change my xsd file with the sex attribute
without sex restrictions it was OK

You need to restrict a simple type as in

<xs:element name="root">
<xs:complexType>
<xs:attribute name="att" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="yes|no" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
 
R

ruthless

thnx - it's working

greetings R

Uzytkownik "Martin Honnen said:
I've got a problem - can I do any restrictions for my attributes?

I found how to restrict elements and was trying to use them with my
attributes

e.g. <person sex="F"> sex can be anly F and M

i've got sth like this:

<xs:complexType name="person-type">
[...]
<xs:attribute name="sex">
<xs:restriction base="xs:string">
<xs:pattern value="F|M"/>
</xs:restriction>
</xs:attribute>
</xs:complexType>

when I valid it using: http://www.w3.org/2001/03/webdata/xsv i recieve info:

* The schema(s) used for schema-validation had no errors

so my scheme is correct or not?
I recieve errors while i'm validating xml + xsd, xsd itself is valid(see
above)

xml is correct i have only change my xsd file with the sex attribute
without sex restrictions it was OK

You need to restrict a simple type as in

<xs:element name="root">
<xs:complexType>
<xs:attribute name="att" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="yes|no" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
 
M

Mike Rawlins

Off the top of my head that ought to work, though there may be something
wrong in the regular express you use to specify the pattern. However,
rather than trying to fix your pattern, the more conventional way to do
what you want is to use the xs:enumeration element for each allowed value.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top