List of utility methods to do XML Document from String
Document | loadDocument(String xmlString) * Load XML document from string ******************************************. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource source = new InputSource(new StringReader(xmlString)); Document doc = db.parse(source); return doc; |
Document | loadXml(String xml) load Xml InputSource inputSource = new InputSource(new StringReader(xml)); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(inputSource); return doc; } catch (Exception ex) { throw new RuntimeException(ex.getMessage(), ex); ... |
org.w3c.dom.Document | loadXMLFrom(String xml) load XML From return loadXMLFrom(new java.io.ByteArrayInputStream(xml.getBytes())); |
Document | loadXMLFromString(String xml) load XML From String DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(xml)); return builder.parse(is); |
Document | loadXMLFromString(String xml) load XML From String try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8"))); } catch (Exception e) { return null; |
Document | loadXMLFromString(String xml) Build Document from String which contains XML content. try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(xml)); return builder.parse(is); } catch (ParserConfigurationException | SAXException | IOException e) { return null; ... |
Document | readString(String xml) read String ensureFactory(); try { DocumentBuilder builder = mFactory.newDocumentBuilder(); return builder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8"))); } catch (Exception e) { if (e instanceof SAXParseException) { SAXParseException spe = (SAXParseException) e; int l = spe.getLineNumber(); ... |