[XPath] namespaces

Dear W3C,

This may be covered or obviated by things already in the XPath 2.0 WD 
(I'm not terribly good at reading the specification documents 
admittedly), but I'd like to bring up some issues with namespaced 
elements--from the perspective of XPath 1.0--in the hopes that they'll 
be addressed in XPath 2.0. Namely, that namespaced elements are 
difficult and clunky to access and it'd be nice to have an easy 
canonical way of accessing them.

Let us take for example an XML document that contains some XHTML. All 
XHTML tags are placed under the "html" namespace in order to easily sort 
them out from the rest of the document. If we have some <html:p> 
elements under the <foo> element, to be accessed they'd need to have 
XPaths like "/foo/child::*[name() = 'html:p']" or if one were being 
technically correct, "foo/child::*[local-name() = 'p' and 
namespace-uri() = 'http://www.w3.org/1999/xhtml']". Neither one of these 
is really simple or accessible.

I'd be nice to have XPaths like "foo/html:p" work. I don't know anything 
about QName, and there may be some other reason why this nomenclature 
wouldn't work, but how about having element names in an XPath step be 
one of:
-- "namespace-name:element-name" (only selects specified element in 
specified namespace),
-- "*:element-name" (selects all specified elements regardless of 
namespace),
-- "element-name" (only select specified elements in the main namespace 
preserving backward compatibility/behavior).

Alternately the latter two could be "element-name" and ":element-name" 
respectively, though that wouldn't preserve behavior. Perhaps even, if 
one were going overboard, you could have the "ns:e", "*:e", and ":e" 
options for specified/any/main namespace and have an option somewhere 
where you could set whether "e" behaves as "*:e" or ":e". That last 
option sounds really nice actually, of course I can't think of a good 
way to deal with specifying the behavior of "e" in XPath alone. How does 
one set XPath 1.0 compatibility mode?

Food for thought. I'd be very interested in knowing how the issue of 
elements under namespaces will be dealt with in XPath 2.0, feel free to 
contact me regarding this matter.

live well,
~wren

Received on Sunday, 10 October 2004 06:46:21 UTC