XSD Restricting Anytype behaviour

B

Brett Gerhardi

Can anyone explain how I can do the following correctly:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="e"/>
<xs:complexType name="ct1">
<xs:choice>
<xs:any namespace="##any"/>
</xs:choice>
</xs:complexType>
<xs:complexType name="ct2">
<xs:complexContent>
<xs:restriction base="ct1">
<xs:choice>
<xs:element name="e1"/>
<xs:element name="e2"/>
</xs:choice>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>

This actually validates ok within XMLSpy within itself, it is just when I
try to validate the following document against it I get the error: "The
content model of complex type ct2 is not a valid restriction of the content
model of complex type ct1

<?xml version="1.0" encoding="UTF-8"?>
<e xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="RestrictingAnytype.xsd"/>

What I would ultimately like to do is express that children of ct1 will only
be of a certain type (in another namespace), but there could be a varying
amount of children. I suppose in programming terms I am looking to express a
typed container.

Is there no way to do this using XSD?

Thanks for any help!
-=- Brett
 
B

Brett Gerhardi

Sorry I copied the wrong version, please make the ct1\anyType unbounded to
see the problem as in the following.

<?xml version="1.0" encoding="UTF-8"?>

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

<xs:element name="e"/>

<xs:complexType name="ct1">

<xs:choice>

<xs:any namespace="##any" maxOccurs="unbounded"/>

</xs:choice>

</xs:complexType>

<xs:complexType name="ct2">

<xs:complexContent>

<xs:restriction base="ct1">

<xs:choice>

<xs:element name="e1"/>

<xs:element name="e2"/>

</xs:choice>

</xs:restriction>

</xs:complexContent>

</xs:complexType>

</xs:schema>
 

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,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top