Newbie: fixed and not-empty element

M

monique

Hi,

I have an enumeration and I would like to fix the value of an element.

A thing like this

<?xml version="1.0"?>
<test>
<single-value>aaa</single-value>
</test>

with the schema:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:element name="test">
<xs:complexType>
<xs:sequence>
<xs:element name="single-value"
type="single-value-type" fixed="aaa" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:simpleType name="single-value-type">
<xs:restriction base="xs:string">
<xs:enumeration value="aaa" />
<xs:enumeration value="bbb" />
<xs:enumeration value="ccc" />
</xs:restriction>
</xs:simpleType>
</xs:schema>

the example validates against the schema and so do this:

<?xml version="1.0"?>
<test>
<single-value/>
<single-value>aaa</single-value>
</test>

I don't want an empty single-value.
What can I do ?


This example

<?xml version="1.0"?>
<test>
<single-value/>
<single-value>aaa</single-value>
<single-value>bbb</single-value>
<single-value>ccc</single-value>
</test>

doesn't validate on bbb and ccc, just as I need.
I would like to get the same on <single-value/>.

Thanks in advance,

Monique
 
S

Stan Kitsis [MSFT]

When an element value is absent, "fixed" acts as "default".

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
G

George Bina

You can use a restriction of your type to that single value:

<xs:element name="single-value" maxOccurs="unbounded">
<xs:simpleType>
<xs:restriction base="single-value-type">
<xs:enumeration value="aaa"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>

Best Regards,
George
 

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,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top