Here you can find the source of stringToDOM(String html)
public static Document stringToDOM(String html)
//package com.java2s; //License from project: Open Source License import java.io.*; import javax.xml.parsers.*; import org.w3c.dom.*; import org.xml.sax.*; public class Main { private static DocumentBuilder builder; public static Document stringToDOM(String html) { if (html.trim().startsWith("<?")) { int pos = html.indexOf("?>"); if (pos > 0) { html = html.substring(pos + 2).trim(); }/*from ww w . j a v a2 s . c o m*/ } html = html.replace("&&", "&&"); InputSource inputSource = new InputSource(new StringReader(html)); try { Document domTree = builder.parse(inputSource); return domTree; } catch (SAXException e) { throw new RuntimeException("Couldn't parse the HTML oder XML code due to a SAXException", e); } catch (IOException e) { throw new RuntimeException("Couldn't parse the HTML oder XML code due to an IOException", e); } } }