Hello,
I am trying to parse an xml page with jtidy. I am having trouble traversing the whole document. I thought I found a solution online, but it throws an error. Here is my code so far (this is a the doGet method of the servlet):
PrintWriter pw = response.getWriter();
String param = request.getParameter("url");
URL url = new URL(param);
Tidy t = new Tidy();
HttpURLConnection u = (HttpURLConnection)url.openConnection();
u.connect();
Document page = t.parseDOM(u.getInputStream(), null);
DocumentTraversal dt = (DocumentTraversal)page;
NodeIterator ni = dt.createNodeIterator(page.getDocumentElement(), NodeFilter.SHOW_ELEMENT, null, true);
for(Node n = ni.nextNode(); n!=null; n=ni.nextNode())
{
pw.print(n.getNodeName());
}
Here is the error when I try to run the code:
java.lang.ClassCastException: org.w3c.tidy.DOMDocumentImpl cannot be cast to org.w3c.dom.traversal.DocumentTraversal
proxy.doGet(proxy.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
Anyone have any experience with this?