Thank you so much! This problem was driving me nuts.
Since you indicate that I should have used the "unique" identifier in this
case, what case might I use the "key" identifier?
Jeff
"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:4291c480$0$14737$9b4e6d93@newsread4.arcor-online.net...[color=blue]
>
>
> Jeff Hosler wrote:
>[color=green]
>> 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?[/color]
>
> As you use a target namespace your XPath expression needs a prefix bound
> to that namespace. There is also the unique element which seems more
> appropriate than a key here:
>
> <xsd:schema
> targetNamespace="http://foobartest"
> xmlns="http://foobartest"
> xmlns:pf1="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:unique name="unique-name">
> <xsd:selector xpath="pf1:bar"/>
> <xsd:field xpath="@name"/>
> </xsd:unique>
> </xsd:element>
>
> <xsd:complexType name="barType">
> <xsd:attribute name="name" type="xsd:string" use="required"/>
> </xsd:complexType>
>
> </xsd:schema>
>
> --
>
> Martin Honnen
>
http://JavaScript.FAQTs.com/[/color]