Unique constraints not working - please help

P

pr

I have the following sample XML File:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<parent>
<child ref="1"><grandchild>tom</grandchild></child>
<child ref="1"><grandchild>harry</grandchild></child>
</parent>

And the schema is:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<xsd:simpleType name = "oneormore">
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="1"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="parent">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="unbounded">
<!-- A chart consists of several rows -->
<xsd:element name="child">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="unbounded">
<xsd:element name="grandchild" type = "xsd:string"/>
</xsd:sequence>
<xsd:attribute name="ref" type="xsd:integer" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<!-- This is not working -->
<xsd:unique name="rowID">
<xsd:selector xpath="parent/child"/>
<xsd:field xpath="@ref"/>
</xsd:unique>
</xsd:element>
</xsd:schema>

The problem is that my XML file validates successfully in my Java
(DOM) app, despite the fact that the values of the ref attributes in
the child element are NOT unique (we have two occurrences of "1").

Is this a bug in the parser, or have I done something wrong in my
schema?
 
P

Pavel Lepin

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<parent>
<child ref="1"><grandchild>tom</grandchild></child>
<child ref="1"><grandchild>harry</grandchild></child>
</parent>

And the schema is:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<xsd:element name="parent">
<xsd:complexType>
[...]

</xsd:complexType>
<!-- This is not working -->
<xsd:unique name="rowID">
<xsd:selector xpath="parent/child"/>
<xsd:field xpath="@ref"/>
</xsd:unique>
</xsd:element>
</xsd:schema>

Is this a bug in the parser, or have I done something
wrong in my schema?

Try and guess. parent element in your document doesn't have
any parent element children.

<xsd:unique name="rowID">
<xsd:selector xpath="child"/>
<xsd:field xpath="@ref"/>
</xsd:unique>
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top