List of utility methods to do XML DOM from String
Document | string2Dom(final String fileContent) string Dom return DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new InputSource(new StringReader(fileContent))); |
Document | string2Dom(String xml) string Dom DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(string2InputSource(xml)); return doc; } catch (Exception e) { System.out.println("caught exception while parsing: " + e); ... |
Document | stringToDOM(String html) string To DOM if (html.trim().startsWith("<?")) { int pos = html.indexOf("?>"); if (pos > 0) { html = html.substring(pos + 2).trim(); html = html.replace("&&", "&&"); InputSource inputSource = new InputSource(new StringReader(html)); ... |
Document | stringToDom(String xmlSource) string To Dom DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(new StringReader(xmlSource))); |
Element | stringToDOM(String xmlString) Transforms a string representation to a DOM representation DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder builder = dbf.newDocumentBuilder(); Reader reader = new StringReader(xmlString); InputSource src = new InputSource(reader); Document domDoc = builder.parse(src); return domDoc.getDocumentElement(); |
Document | stringToDOM(String xmlString) string To DOM try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(new StringReader(xmlString))); } catch (Throwable t) { throw new RuntimeException("Error while building document"); |