方法一:
public Element getDocumentElement(InputStream inputStream, String fileName) {
DocumentBuilder db;
try {
db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
if (db == null) {
return null;
}
return db.parse(inputStream).getDocumentElement();
} catch (Exception e) {
log(fileName, e);
}
return null;
}
方法二:
SAXReader saxReader = new SAXReader();
Document doc = saxReader.read(new File(“fileName”));
Element root = doc.getRootElement();