Page 1 of 1

XPath/Namespace bug...

Posted: Wed Jan 29, 2003 10:35 pm
by TheIdeaMan
To select elements using the XPath field from a document that has mixed namespaces you have to use an "empty" namespace to select elements from the defaul namespace.

Example

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:dc="http://purl.org/dc/1.0">
<head>
<title>My Page</title>
<dc:Author>Benjamin Young</dc:Author>
</head>
....
</html>

To select the "dc:Author" element I can use //dc:Author.
To select the html "title" element I have to us //:title.

It would be best to remove the need to use a ":" when selecting from the default namespace.

Thanks,
:idea:

Posted: Thu Jan 30, 2003 9:53 am
by george
Hi,

There is no specified way to select elements from the default namespace using XPath, the fact that you can do this with <oXygen/> using ":" before the element name is just a Xalan side effect - so it is not portable. You should define a proxy for the default namespace and use that in your XPath:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:dc="http://purl.org/dc/1.0">

and use //html:title

If en element appears in an XPath without proxy then this means it is from no namespace, so we cannot change this to be the default namespace.

Best Regards,
George