Here you can find the source of parseXml(String xmlString)
Parameter | Description |
---|---|
ParserConfigurationException | an exception |
IOException | an exception |
SAXException | an exception |
public static Document parseXml(String xmlString) throws ParserConfigurationException, SAXException, IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayInputStream; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Main { /**// w w w . ja v a2 s. c om * Parse xml string returned from received from a gateway application * @throws ParserConfigurationException * @throws IOException * @throws SAXException */ public static Document parseXml(String xmlString) throws ParserConfigurationException, SAXException, IOException { // Remove three lines before prolog 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); // Create document DocumentBuilder and Document from the xmlString DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); ByteArrayInputStream input = new ByteArrayInputStream(xmlString.getBytes("UTF-8")); Document doc = builder.parse(input); return doc; } }