dom解析xml的简单实例
2011-07-14 20:02
330 查看
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());
}
}
相关文章推荐
- Java解析XML文档(简单实例)——dom解析xml
- Java解析XML文档(简单实例)——dom解析xml
- Java中Dom解析xml的一个实例
- DOM解析XML实例
- C#.NET解析XML(简单实例)
- DOM解析XML文档实例之学生管理系统
- DOM解析Xml实例
- C#.NET解析XML(简单实例)
- JQuery解析XML数据的几个简单实例
- DOM、JDOM、DOM4J解析XML实例
- DOM解析XML简单示例(备忘)
- XML(一) DOM解析XML文档实例一
- dom4j 对xml文件循环解析简单实例
- xmlpull 解析 xml 的简单实例
- php解析xml简单实例
- Ruby nokogiri 解析xml的简单实例
- 简单谈谈dom解析xml和html
- 简单的DOM解析XML文件,并实现增,删,改,查的操作
- JAVA DOM生成和解析XML实例
- DOM解析XML文件实例