Hi friend,
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
public class xmlRead{
static public void main(String[] arg) {
try{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter XML file name: ");
String xmlFile = buff.readLine();
File file = new File(xmlFile);
if (file.exists()){
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(xmlFile);
Transformer tf = TransformerFactory.newInstance().newTransformer();
tf.setOutputProperty(OutputKeys.METHOD, "text");
Source source = new DOMSource(doc);
Result result = new StreamResult(System.out);
tf.transform(source, result);
Node node = doc.getDocumentElement();
String root = node.getNodeName();
System.out.println("Root Node: " + root);
}
else{
System.out.println("File not found!");
}
}
catch (Exception e){
System.err.println(e);
System.exit(0);
}
}
}
---------------------------------------
For read more information at:
http://www.roseindia.net/xml/Thanks & regards
Amardeep