[xml] XML Schema, unique and namespaces
- From: allan awn dk
- To: xml gnome org
- Subject: [xml] XML Schema, unique and namespaces
- Date: Mon, 12 Apr 2010 20:11:15 +0200 (CEST)
Hey,
I'am trying to write a xml schema which must validate that a given
attribute is unique.
A (valid) simple example of the problem could look like this:
<root xmlns="http://ns2" >
<a id="a/1" />
<a id="a/2" >
<a id="a/3" />
<a id="a/4"/>
</a>
</root>
An invalid example (where the ID field is not unique) could look like this:
<root xmlns="http://ns2" >
<a id="a/1" />
<a id="a/2" >
<a id="a/1" />
<a id="a/4"/>
</a>
</root>
The schema I have been experimenting with looks like this:
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ptt="http://ns2"
targetNamespace="http://ns2"
elementFormDefault="qualified" >
<xsd:element name="root" type="ptt:myList">
<xsd:unique name="myId">
<xsd:selector xpath="ptt:*"/>
<xsd:field xpath="@id"/>
</xsd:unique>
</xsd:element>
<xsd:complexType name="myList">
<xsd:sequence minOccurs="1">
<xsd:element name="a" minOccurs="1" maxOccurs="unbounded"
type="ptt:asdf" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="asdf">
<xsd:sequence minOccurs="1">
<xsd:element name="a" minOccurs="0" maxOccurs="unbounded"
type="ptt:asdf" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
I belive my problem is, that I can not figure out the correct xpath to
write in the
selector.
Best regards
Allan W. Nielsen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]