Key-keyref to attribute in root element

  • Thread starter Russell O'Connor
  • Start date
R

Russell O'Connor

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.
 
M

Martin Honnen

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.
 
H

Henry S. Thompson

XSV is happy with your example as written, and rejects e.g.

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

--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: (e-mail address removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 
R

Russell O'Connor

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>
 
M

Martin Honnen

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
 
H

Henry S. Thompson

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
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: (e-mail address removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 

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,962
Messages
2,570,134
Members
46,690
Latest member
MacGyver

Latest Threads

Top