Key-keyref to attribute in root element

Russell O'Connor

Usenet Archive
Joined
Mar 5, 2004
Messages
2
Reaction score
0
The following XML and Schema doesn't validate in Visual Studio .NET 2003. Is there some mistake I'm making, or is VS.NET in error.
The error is

r:\test2.xml(3): The key sequence 'foo' in Keyref fails to refer to some key. An error occurred at , (3, 6).

Any help is appreciated. Here is the schema.

<?xml version="1.0" ?>
<xs:schema id="NewDataSet" targetNamespace="http://tempuri.org/test2.xsd" xmlns:mstns="http://tempuri.org/test2.xsd" xmlns="http://tempuri.org/test2.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:element name="root"> <xs:complexType> <xs:sequence> <xs:element name="object" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="ref" form="unqualified" type="xs:string" /> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="key" form="unqualified" type="xs:string" /> </xs:complexType> <xs:key name="rootKey1"> <xs:selector xpath="." /> <xs:field xpath="@key" /> </xs:key> <xs:keyref name="rootobject" refer="mstns:rootKey1"> <xs:selector xpath=".//mstns:eek:bject" /> <xs:field xpath="@ref" /> </xs:keyref> </xs:element> </xs:schema>

And the XML file that fails to validate is:

<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://tempuri.org/test2.xsd" key="foo"> <object ref="foo" /> </root>

Thanks for any help.
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Russell said:
The following XML and Schema doesn't validate in Visual Studio .NET 2003. Is there some mistake I'm making, or is VS.NET in error.
The error is

r:\test2.xml(3): The key sequence 'foo' in Keyref fails to refer to some key. An error occurred at , (3, 6).

Any help is appreciated. Here is the schema.

<?xml version="1.0" ?>
<xs:schema id="NewDataSet" targetNamespace="http://tempuri.org/test2.xsd" xmlns:mstns="http://tempuri.org/test2.xsd" xmlns="http://tempuri.org/test2.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:element name="root"> <xs:complexType> <xs:sequence> <xs:element name="object" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="ref" form="unqualified" type="xs:string" /> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="key" form="unqualified" type="xs:string" /> </xs:complexType> <xs:key name="rootKey1"> <xs:selector xpath="." /> <xs:field xpath="@key" /> </xs:key> <xs:keyref name="rootobject" refer="mstns:rootKey1"> <xs:selector xpath=".//mstns:eek:bject" /> <xs:field xpath="@ref" /> </xs:keyref> </xs:element> </xs:schema>

And the XML file that fails to validate is:

<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://tempuri.org/test2.xsd" key="foo"> <object ref="foo" /> </root>

When I try Xerces J (as provided in jEdit) I don't get any validation errors.
 

Russell O'Connor

Usenet Archive
Joined
Mar 5, 2004
Messages
2
Reaction score
0
The following seems legal to me, but I can't get MSXML or XMLSPY to validate this properly. Is it valid for me to have a keyref attribute refer to a fixed (but hidden) name?

Here is the schema:

<?xml version="1.0" ?>
<xs:schema id="NewDataSet" targetNamespace="http://tempuri.org/test2.xsd" xmlns:mstns="http://tempuri.org/test2.xsd" xmlns="http://tempuri.org/test2.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:element name="root"> <xs:complexType> <xs:sequence> <xs:element name="object" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="ref" form="unqualified" type="xs:string" /> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="key" form="unqualified" type="xs:string" fixed="foo" /> </xs:complexType> <xs:key name="rootKey1"> <xs:selector xpath="." /> <xs:field xpath="@key" /> </xs:key> <xs:keyref name="rootobject" refer="mstns:rootKey1"> <xs:selector xpath=".//mstns:eek:bject" /> <xs:field xpath="@ref" /> </xs:keyref> </xs:element> </xs:schema>

and here is the XML.

<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://tempuri.org/test2.xsd">
<object ref="foo" />
</root>
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Russell said:
The following seems legal to me, but I can't get MSXML or XMLSPY to validate this properly. Is it valid for me to have a keyref attribute refer to a fixed (but hidden) name?

Here is the schema:

<?xml version="1.0" ?>
<xs:schema id="NewDataSet" targetNamespace="http://tempuri.org/test2.xsd" xmlns:mstns="http://tempuri.org/test2.xsd" xmlns="http://tempuri.org/test2.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:element name="root"> <xs:complexType> <xs:sequence> <xs:element name="object" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="ref" form="unqualified" type="xs:string" /> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="key" form="unqualified" type="xs:string" fixed="foo" /> </xs:complexType> <xs:key name="rootKey1"> <xs:selector xpath="." /> <xs:field xpath="@key" /> </xs:key> <xs:keyref name="rootobject" refer="mstns:rootKey1"> <xs:selector xpath=".//mstns:eek:bject" /> <xs:field xpath="@ref" /> </xs:keyref> </xs:element> </xs:schema>

and here is the XML.

<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://tempuri.org/test2.xsd">
<object ref="foo" />
</root>

I don't get any errors with Xerces J.
With MSXML 4 and 5 I get an error for the missing key, not for the keyref. And the .NET validator complaints about a keyref not referencing a key:
http://apps.gotdotnet.com/xmltools/xsdvalidator/Default.aspx
 

Henry S. Thompson

Usenet Archive
Joined
Jan 14, 2000
Messages
309
Reaction score
0
XSV is happy with your example docs, and unhappy if I change the 'fixed' attr to a different value.

The REC explicitly notes that e.g. keys can be satisfied by default or fixed values supplied by value constraints.

ht
 

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

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top