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

📄 xmlparserdomformat.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");
out.println("<table border=1 width='100%'> ");
out.println("<th>编号</th><th>姓名</th>");
out.println("<th>电话</th><th>邮件</th>");
for(int i=0;i<theNodeList.getLength();i++)
{    
Element theChildElement = (Element)theNodeList.item(i) ;     
NodeList theChildNodeList  = null ;     
String outString ="" ;    
out.println("<tr><td>");     
theChildNodeList=theChildElement.getElementsByTagName("customerid");    
outString = (theChildNodeList.item(0)).getFirstChild().getNodeValue() ;    
out.println(outString +"<br>")  ;        
out.println("</td><td>");      
//    
theChildNodeList=theChildElement.getElementsByTagName("customername");    
outString = (theChildNodeList.item(0)).getFirstChild().getNodeValue() ;    
out.println(outString +"<br>")  ;           
out.println("</td><td>");       
//    
theChildNodeList=theChildElement.getElementsByTagName("tel");    
outString = (theChildNodeList.item(0)).getFirstChild().getNodeValue() ;    
out.println(outString +"<br>")  ;      
out.println("</td><td>");         
//   
theChildNodeList=theChildElement.getElementsByTagName("email");    
outString = (theChildNodeList.item  (0)).getFirstChild().getNodeValue() ;    
out.println(outString +"<br>")  ;                 
out.println("</td></tr>");     
}    
%>
</tr>
</table>
</body>
</html>

⌨️ 快捷键说明

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