I can not get TagSoup to work. I use the following code, but when I print the Node returned by the parser (line with System.err.println (doc);), I always get "[#document: null]".
I don’t know how to find the error in this code or, depending on what it is, the origin of the problem. Please, help!
public final Document parseDOM(final File fileToParse) {
Parser p = new Parser();
SAX2DOM sax2dom = null;
org.w3c.dom.Node doc = null;
try {
URL url = new URL("http://stackoverflow.com/");
p.setFeature(Parser.namespacesFeature, false);
p.setFeature(Parser.namespacePrefixesFeature, false);
sax2dom = new SAX2DOM();
p.setContentHandler(sax2dom);
p.parse(new InputSource(new InputStreamReader(url.openStream())));
doc = sax2dom.getDOM();
System.err.println(doc);
} catch (Exception e) {
e.printStackTrace();
}
return doc.getOwnerDocument();
}
source
share