Here you can find the source of getDocument(InputStream input)
Parameter | Description |
---|---|
input | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static Document getDocument(InputStream input) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayInputStream; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; public class Main { /**/*w ww .j a v a2 s . co m*/ * Get xml document, by stream * * @param input * @return * @throws Exception */ public static Document getDocument(InputStream input) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(input); return doc; } /** * Get xml document, by xml string * * @param xml * @return * @throws Exception */ public static Document getDocument(String xml) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes())); return doc; } }