Java XML Document Parse parseXmlDocument(InputStream is, boolean namespaceAware)

Here you can find the source of parseXmlDocument(InputStream is, boolean namespaceAware)

Description

parse Xml Document

License

Apache License

Declaration

public static Document parseXmlDocument(InputStream is, boolean namespaceAware)
            throws ParserConfigurationException, SAXException, IOException 

Method Source Code


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

import java.io.IOException;
import java.io.InputStream;

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 {
    public static Document parseXmlDocument(InputStream is, boolean namespaceAware)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilder docBuilder = buildDocumentBuilder(namespaceAware);
        Document doc = docBuilder.parse(is);

        // normalize text representation
        doc.getDocumentElement().normalize();

        return doc;
    }/*  w w  w. j  a  v a2 s . c o  m*/

    private static DocumentBuilder buildDocumentBuilder(boolean namespaceAware)
            throws ParserConfigurationException {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        docBuilderFactory.setNamespaceAware(namespaceAware);
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        return docBuilder;
    }
}

Related

  1. parseMultipleWorkouts(Document doc)
  2. parseResponse(InputSource is, DocumentBuilder documentBuilder)
  3. parseToDocument(InputStream is, boolean debugModeEnabled)
  4. parseXMLDoc(Element element, Document doc, Map oauthResponse)
  5. parseXmlDocToString(Document xmlDoc)
  6. parseXMLDocument(String xml)
  7. parseXmlDocument(String xml, boolean namespaceAware)
  8. parseXMLDocument(String xmlDoc)
  9. parseXMLDocument(String xmlResponse)