XPath/Namespace bug...

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.

XPath/Namespace bug...

Wed Jan 29, 2003 10:35 pm

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.


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

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.

Site Admin
Posts: 2100

Thu Jan 30, 2003 9:53 am


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,

Return to “Common Problems”

Who is online

Users browsing this forum: No registered users and 0 guests