Yet another common question is how one parses a byte array of XML into a DOM Document object. Here's a method that does just that:
import java.i
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
public class Util {
public static Document bytesToXml(byte[] xml)
throws SAXException, ParserConfigurationException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(new ByteArrayInputStream(xml));
}
}
XmlFaq CategoryCodeSamples