⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlparserdom.jsp

📁 jsp动态网站开发与实例(第3版) 源码
💻 JSP
字号:
<%@page contentType="text/html"%>
<%@page pageEncoding="ms950"%>
<%@page import="javax.xml.parsers.*" %>
<%@page import="org.w3c.dom.*" %><html>    
<head><title>解译 XML</title></head>    
<body>    
<%                 
DocumentBuilderFactory theDocumentBuilderFactory=                 
DocumentBuilderFactory.newInstance() ;         
DocumentBuilder theDocumentBuilder =                 
theDocumentBuilderFactory.newDocumentBuilder() ;         
Document theDocument = theDocumentBuilder.parse(request.getRealPath("/"+"ch12//xmlFile//customers.xml")) ;        
Element theParentElement = theDocument.getDocumentElement() ;               
NodeList theNodeList =theParentElement.getElementsByTagName("customer");               
for(int i=0;i<theNodeList.getLength();i++){            
Element theChildElement = (Element)theNodeList.item(i) ;             
NodeList theChildNodeList  = null ;             
String outString ="" ;             
//            
theChildNodeList=theChildElement.getElementsByTagName("customerid");            
outString = (theChildNodeList.item(0)).getFirstChild().getNodeValue() ;            
out.println("编号:"+outString +"<br>")  ;             
//            
theChildNodeList=theChildElement.getElementsByTagName("customername");            
outString = (theChildNodeList.item(0)).getFirstChild().getNodeValue() ;            
out.println("姓名:"+outString +"<br>")  ;             
//            
theChildNodeList=theChildElement.getElementsByTagName("tel");            
outString = (theChildNodeList.item(0)).getFirstChild().getNodeValue() ;            
out.println("电话:"+outString +"<br>")  ;                        
//            
theChildNodeList=theChildElement.getElementsByTagName("email");            
outString = (theChildNodeList.item  (0)).getFirstChild().getNodeValue() ;            
out.println("电子邮件:"+outString +"<br>")  ;             
out.println("========================================<br>") ;         
}        
%>    
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -