Thank you Dave,

> 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.

Okay, I made some modifications to the code...I kicked out JTidy and directly 
parse the JTidy result using DocumentHelper, select the Node and check nulls.

Is it correct, that the 'document.selectSingleNode("/html/body")' at the 
bottom return null ? Is the XPath-Expression wrong ? I tried in XPE a similar 
example - works without problems.

any suggestions ?

Marco

----%<------
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;

public class TestTidyDom4j2
{
    public static void main(String[] args)
    {
        String page=
        new StringBuffer()
        .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
        .append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" ")
        .append("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>")
        .append("<html xmlns=\"http://www.w3.org/1999/xhtml\";>")
        .append("<head xmlns=\"\">")
        .append("<meta content=\"HTML Tidy, see www.w3.org\" 
name=\"generator\"/>")
        .append("<title>Test</title>")
        .append("</head>")
        .append("<body xmlns=\"\">")
        .append("<h1>This is a test</h1>")
        .append("</body>")
        .append("</html>")
        .toString();

        Document document= null;
        try
        {
            document= DocumentHelper.parseText(page);
        }
        catch (DocumentException de)
        {
            de.printStackTrace();
        }
        System.err.println(document.asXML());

        if (document.selectSingleNode("/html/body") == null)
            System.err.println("table is null");
    }
}
----->%-------

Output:
-----%<--------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";><html 
xmlns="http://www.w3.org/1999/xhtml";><head xmlns=""><meta content="HTML Tidy, 
see www.w3.org" name="generator"/><title>Test</title></head><body 
xmlns=""><h1>This is a test</h1></body></html>
table is null
----->%---------



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

Reply via email to