Parse html document with NekoHTML

4.7k Views Asked by At

I am using NekoHTML framework with xerces 2.11.0 version to parse an HTML document. But i am having a problem with this simple code :

DOMParser parser = new DOMParser();
System.out.println(parser.getClass().toString());
InputSource url = new InputSource("http://www.cbgarden.org");
try{
    parser.parse(url);
    Document document = parser.getDocument();
    System.out.println(document.hasChildNodes());
    System.out.println(document.getBaseURI());
    System.out.println(document.getNodeName());
    System.out.println(document.getNodeValue());
}catch(Exception e){
    e.printStackTrace();
}

Now I put here the result of the multiple prints:

  1. class org.cyberneko.html.parsers.DOMParser
  2. true
  3. http://www.cbgarden.org
  4. document
  5. null

So my question is : What could be wrong ? No exception is thrown and I am following the rules that are defined in the usage rules in the NekoHTML. My build path libraries are with this precedence:

  1. nekohtml.jar
  2. nekohtmlSamples.jar
  3. xercesImpl.jar
  4. xercesSamples.jar
  5. xml-apis.jar
1

There are 1 best solutions below

1
On

I guess your question is about the null?
The document node has no value. It only has subnodes (like <html> witch contains <head> and <body>).

But if you want to have the whole page source as a String, you can simply download it using a URL its method openStream().