xs:key effective across xi:includes?

D

daldridge

I don't know if what I want to do is possible or not, but I'd like to
have an xs:key in my schema that constrains attributes directly in a
document, as well as those in another document, included in the
first. Here's an example of what I'm trying to say:

FooList.xsd:
================
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:FooList="http://www.somecompany.com/FooList"
targetNamespace="http://www.somecompany.com/FooList"
xmlns="http://www.trionworld.com" elementFormDefault="qualified">

<xs:import namespace="http://www.w3.org/2001/XInclude"
schemaLocation="http://www.w3.org/2001/XInclude.xsd"/>

<!-- Range-limited data type for 'Bar' attributes on 'Foo's. An
xs:key will
constrain the value to be unique (can you extend/restrict xs:ID to
specify
both min and max? ...). -->
<xs:simpleType name="BarAttr">
<xs:restriction base="xs:nonNegativeInteger">
<xs:minExclusive value="0"/>
<xs:maxInclusive value="65535"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="Foo">
<xs:attribute name="Bar" type="FooList:BarAttr" use="required"/>
</xs:complexType>

<xs:element name="FooList">
<xs:complexType>
<xs:sequence minOccurs="0">
<xs:element ref="xi:include" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="Foo" type="FooList:Foo" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:key name="PK_FooBar">
<xs:selector xpath="FooList:Foo"/>
<xs:field xpath="@bar"/>
</xs:key>
</xs:element>

</xs:schema>


FooListA.xml
==========
<?xml version="1.0" encoding="UTF-8"?>
<FooList xmlns="http://www.somecompany.com/FooList"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.somecompany.com/FooList FooList.xsd">

<Foo Bar="1"/>
<Foo Bar="2"/>

</FooList>


FooListB.xml
==========
<?xml version="1.0" encoding="UTF-8"?>
<FooList xmlns="http://www.somecompany.com/FooList"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.somecompany.com/FooList FooList.xsd">

<include xmlns="http://www.w3.org/2001/XInclude" href="FooListA.xml"
xpointer="FooList:FooList"/>

<Foo Bar="1"/>
<Foo Bar="2"/>

</FooList>


Essentially, I would like validation of FooListB.xml to fail, given
that it has 'Bar' attribute values which conflict with those in
FooListA.xml (assuming my include directive is correct...?). I'm
basically trying to "merge" document fragments into a master document,
and have the key constraint be useful.

Is this possible?

Cheers,
-David
 

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,999
Messages
2,570,246
Members
46,843
Latest member
WizcraftEntertainmentAgen

Latest Threads

Top