List of utility methods to do XML Element from String
Element | stringToElement(final String inputXml) Convert XML string to Element. try { final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); final Document document = builder.parse(new ByteArrayInputStream(inputXml.getBytes("UTF-8"))); return document.getDocumentElement(); } catch (ParserConfigurationException ex) { throw new IOException("IgapyonXmlUtil#stringToElement: Fail to configure xml parser: ", ex); } catch (SAXException ex) { throw new IOException("IgapyonXmlUtil#stringToElement: Fail to process xml: ", ex); ... |
Element | stringToElement(String s) Convert the String representation of an Element into an Element return stringToElement(s, false);
|
Element | stringToElement(String xml) Converts a String representing an XML snippet into an org.w3c.dom.Element . ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes("utf8")); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document d = builder.parse(bais); bais.close(); return d.getDocumentElement(); |