[xsd-users] Defining key and key ref
Carmi, Eyal (Eyal)
carmi at avaya.com
Sun Feb 26 09:06:59 EST 2006
Strange, Are you aware of a bug in XMLSpy (I'm using it as my
editor/validate) that may cause this problem? (It shows that the XML is
valid...)
Anyways,
Thank you very much.
-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com]
Sent: Sunday, February 26, 2006 3:46 PM
To: Carmi, Eyal (Eyal)
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] Defining key and key ref
Eyal,
Carmi, Eyal (Eyal) <carmi at avaya.com> writes:
> It validates even though the pKey 'A' appears twice... I also tried
> defining 'pKey' as an element (instead of attribute) but the results
> are the same.
I tried your schema and test xml with xsd-1.9.0 and xerces-c-2.7.0 and
everything works as expected:
test.xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MyFilters">
<xs:complexType>
<xs:sequence>
<xs:element name="Filter" type="FilterType" minOccurs="0"
maxOccurs="4"/>
</xs:sequence>
</xs:complexType>
<xs:key name="FilterKey">
<xs:selector xpath="Filter"/>
<xs:field xpath="@pKey"/>
</xs:key>
</xs:element>
<xs:complexType name="FilterType">
<xs:sequence>
<xs:element name="data1" type="xs:integer"/>
<xs:element name="data2" type="xs:integer" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="pKey" type="xs:string"/> </xs:complexType>
</xs:schema>
test.xml:
<MyFilters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<Filter pKey="A">
<data1>-0</data1>
<data2>-0</data2>
</Filter>
<Filter pKey="A">
<data1>-0</data1>
<data2>-0</data2>
</Filter>
</MyFilters>
driver.cxx:
#include <iostream>
#include "test.hxx"
int
main ()
{
try
{
MyFilters ("test.xml");
}
catch (xml_schema::parsing const& e)
{
std::cerr << e << std::endl;
return 1;
}
}
$ xsd cxx-tree test.xsd
$ g++ driver.cxx test.cxx -lxerces-c
$ ./driver
/tmp/test.xml:9:20 error: Duplicate key value declared for identity
constraint of element 'MyFilters'.
hth,
-boris
More information about the xsd-users
mailing list