Key-keyref to attribute in root element

Discussion in 'XML' started by Russell O'Connor, Mar 5, 2004.

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

    --
    Russell
     
    Russell O'Connor, Mar 5, 2004
    #1
    1. Advertising

  2. Russell O'Connor wrote:

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

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Mar 5, 2004
    #2
    1. Advertising

  3. 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:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
     
    Henry S. Thompson, Mar 6, 2004
    #3
  4. Key-keyref to fixed attribute (Was: Key-keyref to attribute in root element)

    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>
     
    Russell O'Connor, Apr 11, 2004
    #4
  5. Re: Key-keyref to fixed attribute (Was: Key-keyref to attribute inroot element)

    Russell O'Connor wrote:

    > 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

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Apr 11, 2004
    #5
  6. Re: Key-keyref to fixed attribute

    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:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
     
    Henry S. Thompson, Apr 27, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marek Malowidzki

    Key/keyref validation in schema?

    Marek Malowidzki, Aug 18, 2003, in forum: XML
    Replies:
    1
    Views:
    522
    Mark Preston
    Aug 19, 2003
  2. J E E
    Replies:
    0
    Views:
    385
    J E E
    Nov 7, 2003
  3. peterpeter
    Replies:
    0
    Views:
    947
    peterpeter
    Feb 11, 2004
  4. Markus Seibold

    <key><keyref> does not work in XMLSpy

    Markus Seibold, Feb 13, 2004, in forum: XML
    Replies:
    0
    Views:
    1,328
    Markus Seibold
    Feb 13, 2004
  5. John Carron
    Replies:
    2
    Views:
    876
    John Carron
    Sep 2, 2005
Loading...

Share This Page