Java tutorial
//package com.java2s; // This software is released under the Apache License 2.0. import org.w3c.dom.*; import javax.xml.parsers.*; import java.io.*; public class Main { public static Document parseXml(File file) throws Exception { return newDocumentBuilder().parse(file); } public static Document parseXml(String xml) throws Exception { return newDocumentBuilder().parse(new ByteArrayInputStream(xml.getBytes("UTF-8"))); } private static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(false); return domFactory.newDocumentBuilder(); } }