Java tutorial
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class Main { public static Document readXMLFromInputStream(InputStream inputStream) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbf; DocumentBuilder db; Document document; dbf = DocumentBuilderFactory.newInstance(); db = dbf.newDocumentBuilder(); Reader reader = new InputStreamReader(inputStream, "UTF-8"); InputSource is = new InputSource(reader); is.setEncoding("UTF-8"); document = db.parse(is); return document; } }