meaning of dot in xpath expressions in keys?

I need to make sure that an attribute in a particular element has the same
value
as an attribute in its child element. In the following example the fact that
the
names of the processes have been accidentally swapped over should be
queried by the schema.

<?xml version="1.0" encoding="UTF-8"?>
<Repository xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:noNamespaceSchemaLocation="M:\MooD\DEV\Sydney\MooDXml\XmlSchemas\brokend
ot.xsd" name="BrokenDot">
    <Context name="1">
        <Process name="2"/> <!-- whoops - this should be inside the context
named "2" -->
    </Context>
    <Context name="2">
        <Process name="1"/>
    </Context>
</Repository>

The following schema works in XML Spy but not the Microsoft XML component
MSXML4 beta 2 (July).

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Process">
    <xs:complexType>
        <xs:attribute name="name" type="xs:string" use="required"/>
    </xs:complexType>
</xs:element>
<xs:element name="Context">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="Process"/>
        </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required"/>
    </xs:complexType>
<xs:key name="ContextNameSingleNodeKey">
    <xs:selector xpath="."/> <!--     What's the meaning of the dot -->
    <xs:field xpath="@name"/>
</xs:key>
<xs:keyref name="ProcessNameMustBeSameAsContextName"
refer="ContextNameSingleNodeKey">
    <xs:selector xpath="Process"/>
    <xs:field xpath="@name"/>
</xs:keyref>
</xs:element>
    <xs:element name="Repository">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Context" minOccurs="0"
maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="name" type="xs:string" use="required"/>
        </xs:complexType>
        <xs:unique name="ContextNamesUnique">
            <xs:selector xpath="./Context"/>
            <xs:field xpath="@name"/>
        </xs:unique>
        <xs:unique name="ProcessNamesUnique">
            <xs:selector xpath=".//Process"/>
            <xs:field xpath="@name"/>
        </xs:unique>
    </xs:element>
</xs:schema>

I think XML Spy has got it right on this occasion. It looks like MSXML4
thinks that the dot in ContextNameSingleNodeKey means "this node and
all sibling nodes of the same type.

What do you think: another bug in the Microsoft component, XML Spy getting
its knickers in a twist or an ambiguity in the W3C standard?

On another, related note: is anybody else finding that many of the
relationship/
constraints/rules in their data are not expressible using XML schema?
Does anybody know if the key/keyref mechanism is going to be improved or
supplemented in any way so that XML schema can describe any
document/database
rather than just a subset?

--
Gaz

Received on Tuesday, 16 October 2001 13:03:11 UTC