Re: [afo@zurich.ibm.com] Interpreting QName in XPath expression for <field> element

ht@cogsci.ed.ac.uk (Henry S. Thompson) writes:

> From: afo@zurich.ibm.com
>
> I would like to have your point of view on the way QName appearing in XPath
> expression for a <field>  should be interpreted.

As specified by the XPath REC [1]

> Here is an example extracted from the primer :
> 
> <schema targetNamespace="http://www.example.com/Report"
>         xmlns="http://www.w3.org/2001/XMLSchema"
>         xmlns:r="http://www.example.com/Report"
>         xmlns:xipo="http://www.example.com/IPO"
>         elementFormDefault="qualified">
> 
> <import namespace="http://www.example.com/IPO"/>
> 
>  <element name="purchaseReport">
>   <complexType>
>    <sequence>
>     <element name="regions" type="r:RegionsType">
>      <keyref name="dummy2" refer="r:pNumKey">
>       <selector xpath="r:zip/r:part"/>
>       <field xpath="@number"/>

XPath is very clear -- all unprefixed names are interpreted as
unqualfied.  So this will match 'number' attributes with no namespace name.

>      </keyref>
>     </element>
> 
>     <element name="parts" type="r:PartsType"/>
>    </sequence>
>    <attribute name="period"       type="duration"/>
>    <attribute name="periodEnding" type="date"/>
>   </complexType>
> 
>  </element>
> 
>  <complexType name="RegionsType">
>   <sequence>
>    <element name="zip" maxOccurs="unbounded">
>     <complexType>
>      <sequence>
>       <element name="part" maxOccurs="unbounded">
>        <complexType>
>         <complexContent>
>          <restriction base="anyType">
>           <attribute name="number"   type="xipo:SKU"/>

This does _not_ define a qualified attribute.  Accordingly, in
conformant instances, the actual AII will have no namespace name.

>           <attribute name="quantity" type="positiveInteger"/>
>          </restriction>
>         </complexContent>
>        </complexType>
>       </element>
>      </sequence>
>      <attribute name="code" type="positiveInteger"/>
>     </complexType>
>    </element>
>   </sequence>
>  </complexType>
> </schema>
> 
> In <field xpath="@number"/>, since the default namespace (the namespace
> without prefix) is http://www.w3.org/2001/XMLSchema, I think "@number"
> refers to the qualified attribute
> {http://www.w3.org/2001/XMLSchema}{number}.

But it doesn't, see above.

> However, there is no such
> attribute in {http://www.example.com/Report}{zip}/
> {http://www.example.com/Report}{part} ("number" attribute defined there is
> unqualified). According to me, this example extracted from the primer is
> invalid.

You have misunderstood how XPath interprets names.  Note that the type 
of the 'xpath' attribute of <xs:field> and <xs:selector> is _not_
QName, but a rather xs:token restricted by an appropriate regexp.

ht

[1] http://www.w3.org/TR/xpath
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
          W3C Fellow 1999--2001, part-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/

Received on Monday, 25 June 2001 10:47:03 UTC