Java XML Document Parse parseXMLDocument(String xmlResponse)

Here you can find the source of parseXMLDocument(String xmlResponse)

Description

Parses XML String

License

Apache License

Parameter

Parameter Description
xmlResponse XML String representation

Exception

Parameter Description

Return

Parsed XML Document

Declaration

public static org.w3c.dom.Document parseXMLDocument(String xmlResponse)
        throws ParserConfigurationException, IOException, SAXException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.StringReader;

public class Main {
    /**//from  w  w  w  .  ja  v  a2  s .  c o m
     * Parses XML String
     * @param xmlResponse XML String representation
     * @return Parsed XML Document
     * @throws javax.xml.parsers.ParserConfigurationException
     * @throws java.io.IOException
     * @throws org.xml.sax.SAXException
     */
    public static org.w3c.dom.Document parseXMLDocument(String xmlResponse)
            throws ParserConfigurationException, IOException, SAXException {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
        factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
        factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);

        DocumentBuilder builder = factory.newDocumentBuilder();

        InputSource is = new InputSource(new StringReader(xmlResponse));

        return builder.parse(is);
    }
}

Related

  1. parseXmlDocToString(Document xmlDoc)
  2. parseXmlDocument(InputStream is, boolean namespaceAware)
  3. parseXMLDocument(String xml)
  4. parseXmlDocument(String xml, boolean namespaceAware)
  5. parseXMLDocument(String xmlDoc)
  6. parseXmlFragmentStr(Document doc, String fragment)
  7. parseXMLString(Document document, String string)