Java XML Parse String parseXml(String xmlString)

Here you can find the source of parseXml(String xmlString)

Description

Parse xml string returned from received from a gateway application

License

Open Source License

Exception

Parameter Description
ParserConfigurationException an exception
IOException an exception
SAXException an exception

Declaration

public static Document parseXml(String xmlString)
        throws ParserConfigurationException, SAXException, IOException 

Method Source Code


//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;
    }
}

Related

  1. parseXml(String xml)
  2. parseXml(String xml)
  3. parseXml(String xml)
  4. parseXML(String xml)
  5. parseXML(String xml)
  6. parseXMLResponse(String xmlStr)
  7. parseXMLString(final String xml)