Java examples for XML:XML Node
read XML Node from InputStream
//package com.java2s; import java.io.File; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Node; public class Main { protected static Node read(InputStream xml) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance();// w ww . j a va 2s. c o m DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(xml).getDocumentElement(); } protected static Node read(File xml) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(xml).getDocumentElement(); } }