List of utility methods to do XML Parse String
Document | parseXml(String xml) Returns a new document for the given XML string. try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); return docBuilder.parse(new InputSource(new StringReader(xml))); } catch (Exception e) { e.printStackTrace(); return null; ... |
Document | parseXml(String xmlString) Parse xml string returned from received from a gateway application xmlString = xmlString.substring(xmlString.indexOf(System.getProperty("line.separator")) + 1); xmlString = xmlString.substring(xmlString.indexOf(System.getProperty("line.separator")) + 1); xmlString = xmlString.substring(xmlString.indexOf(System.getProperty("line.separator")) + 1); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); ByteArrayInputStream input = new ByteArrayInputStream(xmlString.getBytes("UTF-8")); Document doc = builder.parse(input); return doc; ... |
Document | parseXMLResponse(String xmlStr) Returns a Document(DOM) object representing the parsed XML. if ((xmlStr == null) || (xmlStr.length() == 0)) { return null; try { DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); return db.parse(new ByteArrayInputStream(xmlStr.getBytes())); } catch (ParserConfigurationException | IOException | SAXException pcex) { return null; |
Element | parseXMLString(final String xml) Reads a string that contains XML markup as a DOM. Document doc; try { DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Reader r = new StringReader(xml); InputSource s = new InputSource(r); doc = docBuilder.parse(s); } catch (SAXParseException err) { throw new Exception("Parse error in '" + xml + "', line " + err.getLineNumber() + ", uri " ... |