Java tutorial
//package com.java2s; 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 { /** * Creates a document from the given xml bytes. * @return The desired document. Never returns null but throws some Exception. * @throws ParserConfigurationException, IOException, SAXException */ public static Document getDocument(byte[] xml) throws ParserConfigurationException, IOException, SAXException { if (xml != null) { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // factory.setNamespaceAware( true ); // factory.setValidating( true ); final DocumentBuilder builder = factory.newDocumentBuilder(); final Document document = builder.parse(new ByteArrayInputStream(xml)); return document; } throw new IOException("No xml data"); } }