public class ParseXML {
public static void main(String[] args) throws Exception{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document d = db.parse("c:/test.xml");
NodeList nl = d.getElementsByTagName("to");
Node n = nl.item(0);
System.out.println(n.getNodeName());
System.out.println(n.getNodeValue());
System.out.println(n.getNodeType());
Node node = n.getFirstChild();
System.out.println(node.getNodeName());
System.out.println(node.getNodeValue());
System.out.println(node.getNodeType());
NodeList nl2 = d.getElementsByTagName("from");
Node n2 = nl2.item(0);
System.out.println(n2.getNodeName());
System.out.println(n2.getNodeValue());
System.out.println(n2.getNodeType());
Node node2 = n2.getFirstChild();
System.out.println(node2.getNodeName());
System.out.println(node2.getNodeValue());
System.out.println(node2.getNodeType());
}
}
public static void main(String[] args) throws Exception{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document d = db.parse("c:/test.xml");
NodeList nl = d.getElementsByTagName("to");
Node n = nl.item(0);
System.out.println(n.getNodeName());
System.out.println(n.getNodeValue());
System.out.println(n.getNodeType());
Node node = n.getFirstChild();
System.out.println(node.getNodeName());
System.out.println(node.getNodeValue());
System.out.println(node.getNodeType());
NodeList nl2 = d.getElementsByTagName("from");
Node n2 = nl2.item(0);
System.out.println(n2.getNodeName());
System.out.println(n2.getNodeValue());
System.out.println(n2.getNodeType());
Node node2 = n2.getFirstChild();
System.out.println(node2.getNodeName());
System.out.println(node2.getNodeValue());
System.out.println(node2.getNodeType());
}
}