XPath/Namespace bug...

Having trouble installing Oxygen? Got a bug to report? Post it all here.
TheIdeaMan

XPath/Namespace bug...

Post 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:
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post 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
Post Reply