<?xml version="1.0" encoding="UTF-8"?>
<addresslist>
<name>李兴华</name>
</addresslist>
import java.io.* ;
import org.w3c.dom.* ;
import javax.xml.parsers.* ;
public class wwee {
public static void main(String args[]) throws Exception {
// 取得DocumentBuilderFactory类的对象
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance() ;
// 取得DocumentBuilder类的对象
DocumentBuilder build = factory.newDocumentBuilder() ;
Document doc = build.parse("123.xml") ;
NodeList nl = doc.getElementsByTagName("name") ;
// 输出节点
System.out.println("姓名:" + nl.item(0).getFirstChild().getNodeValue()) ;
}
}
相关分类