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 why...
Thanks in advance
Marco
----%<-------
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.DOMReader;
import org.w3c.tidy.Tidy;
public class TestTidyDom4j
{
public static void main(String[] args)
{
String page=
new StringBuffer()
.append("<html>")
.append("<head>")
.append("<title>")
.append("Test")
.append("</title>")
.append("</head>")
.append("<body>")
.append("<h1>This is a test</h1>")
.append("</body>")
.append("</html>")
.toString();
// make HTML to XHTML
Tidy tidy= new Tidy();
tidy.setXHTML(true);
InputStream in= new ByteArrayInputStream(page.getBytes());
org.w3c.dom.Document xhtml= tidy.parseDOM(in, null);
// translate DOM for dom4j
DOMReader xmlReader= new DOMReader();
Document document= xmlReader.read(xhtml);
Node table= document.selectSingleNode("/html/body");
System.err.println("table : " + table.asXML());
// ^^^^^ here is a
// NullPointerException is thrown
}
}
----->%--------
-------------------------------------------------------
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user