import javax.xml.parsers.*;
import org.w3c.dom.*;public class dom{
public static void main(String[] args){
try{
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc=builder.parse("candidate.xml");
NodeList nl=doc.getElementsByTagName("PERSON");
for(int i=0;i<nl.getLength();i++){
Element node=(Element)nl.item(i);
System.out.print("NAME: ");
System.out.println(node.getElementsByTagName("NAME").item(0).getFirstChild().getNodeValue());
System.out.print("ADDRESS: ");
System.out.println(node.getElementsByTagName("ADDRESS").item(0).getFirstChild().getNodeValue());
System.out.print("TEL: ");
System.out.println(node.getElementsByTagName("TEL").item(0).getFirstChild().getNodeValue());
System.out.print("FAX: ");
System.out.println(node.getElementsByTagName("FAX").item(0).getFirstChild().getNodeValue());
System.out.print("EMAIL: ");
System.out.println(node.getElementsByTagName("EMAIL").item(0).getFirstChild().getNodeValue());
System.out.println();
}
}catch(Exception e){
e.printStackTrace();
}
}
}
import org.w3c.dom.*;public class dom{
public static void main(String[] args){
try{
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc=builder.parse("candidate.xml");
NodeList nl=doc.getElementsByTagName("PERSON");
for(int i=0;i<nl.getLength();i++){
Element node=(Element)nl.item(i);
System.out.print("NAME: ");
System.out.println(node.getElementsByTagName("NAME").item(0).getFirstChild().getNodeValue());
System.out.print("ADDRESS: ");
System.out.println(node.getElementsByTagName("ADDRESS").item(0).getFirstChild().getNodeValue());
System.out.print("TEL: ");
System.out.println(node.getElementsByTagName("TEL").item(0).getFirstChild().getNodeValue());
System.out.print("FAX: ");
System.out.println(node.getElementsByTagName("FAX").item(0).getFirstChild().getNodeValue());
System.out.print("EMAIL: ");
System.out.println(node.getElementsByTagName("EMAIL").item(0).getFirstChild().getNodeValue());
System.out.println();
}
}catch(Exception e){
e.printStackTrace();
}
}
}
解决方案 »
- 【IE 火狐的问题:new Date()函数问题 】
- 1、url是直接在firefox浏览器的地址栏内手动输入,不是在jsp页面上,因此不能直接对id使用函数编码;2、我想统一编码用utf-8,因此不可以用gbk编
- 用JSP如何实现文件夹时。自动打包上传
- 在一个JSP页面中嵌套一个应用程序窗口
- 用JB9开发大型网站是否实用,采用struts框架。
- servlet中文问题
- 这个问题弄得我一头雾水!
- Struts乱码问题!!!!!
- struts在显示时,用什么标签进行格式化数据,如对数字进行保留多少位并四舍五入?
- 关于字符串日期的转换!
- javaMail 问题,高手指点迷津
- 能否实现bgcolor 的颜色渐变
不知道怎么做! 谢谢各位了啊!
你去javaresearch.org去找一下。我记得里面曾经是有讲这方面的。
我记得在oracle 8 有这个功能.