Title: Xpath and Namespaces
Hi,
I have noticed that the DOM4J examples XPathTool.java does not work if the Xpath is defined inline rather than in the outside node of the file.
So
root xmlns:as=url
as:elt/
/root
With xpath //as:elt will work but if you try it against:
Hi,
I want to use XPath Expressions on a HTML page. I use
JTidy to convert a page into XHTML. This XHTML can be
easily transformed into a dom4j Document.
My current problem is that I get a NullPointerException
if I try to access any Node in the page using a XPath
Expression. I don't understand
Marco,
After looking at the code, I am not sure you realize that
document.selectSingleNode will return null if the expression is not
found. This probably why it was a null pointer exception.
Try checking if (table!=null) before processing it.
Also take a look at XPE at
Did you test with the complete file or just a snippet?
You have a default namespace defined in the root.
.append(html xmlns=\http://www.w3.org/1999/xhtml\;)
You may want to use the /*[local-name()='html']/*[local-name()='body']
to avoid the namespace all together.
Give that a try.