J
Jeff Hosler
I am trying to get an XML schema to validate unique key name attributes, and
have been unsuccessful. Can anyone show me what I am doing wrong?
Here is the schema:
<xsd:schema
targetNamespace="http://foobartest"
xmlns="http://foobartest"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xsd:element name="foo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="bar" type="barType" minOccurs="1"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:key name="bar_key">
<xsd:selector xpath=".//bar"/>
<xsd:field xpath="@name"/>
</xsd:key>
</xsd:element>
<xsd:complexType name="barType">
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:schema>
-----------------------
Here is the XML file that should report being invalid:
<?xml version="1.0" encoding="UTF-8"?>
<foo
xmlns="http://foobartest"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://foobartest foo.xsd">
<bar name="One"/>
<bar name="Two"/>
<bar name="Three"/>
<bar name="One"/>
</foo>
----------------------------
The XML file should fail, but does not. Can anyone show me what is
incorrect in my schema?
Thank you for your help.
Jeff
have been unsuccessful. Can anyone show me what I am doing wrong?
Here is the schema:
<xsd:schema
targetNamespace="http://foobartest"
xmlns="http://foobartest"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xsd:element name="foo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="bar" type="barType" minOccurs="1"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:key name="bar_key">
<xsd:selector xpath=".//bar"/>
<xsd:field xpath="@name"/>
</xsd:key>
</xsd:element>
<xsd:complexType name="barType">
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:schema>
-----------------------
Here is the XML file that should report being invalid:
<?xml version="1.0" encoding="UTF-8"?>
<foo
xmlns="http://foobartest"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://foobartest foo.xsd">
<bar name="One"/>
<bar name="Two"/>
<bar name="Three"/>
<bar name="One"/>
</foo>
----------------------------
The XML file should fail, but does not. Can anyone show me what is
incorrect in my schema?
Thank you for your help.
Jeff