本科实验报告
课程名称:      Web系统与技术           
实验项目:        xml操作                 
实验地点:         致远楼301      
专业班级: 软件工程1222       学号:2012005612
学生姓名:            王兆晖           
指导教师:      师锋洋             
2015 年1 月17

一、实验目的
  掌握XML语法,学会XML操作
实验要求
1独立完成实验
2书写实验报告书
实验内容
1、编写程序。
1)程序:课本P290习题11.8。
要求:对应的XML文档内容为:
<?xml version="1.0"encoding="GB2312"?>   
<?xml-stylesheet type=“text/xsl” href=“test.xsl”?>   
<addresslist>           
    <linkman>           
        <name>李兴华</name>
        <id>001</id>               
    </linkman>       
</addresslist>
要求:李兴华和001之间间隔1行。
2)程序:课本P290习题11.10。
<?xml version="1.0" encoding="GBK"?>
<addresslist>
    <linkman>
        <name>李兴华</name>
        <email>mldnqa@163</email>error parse new
    </linkman>
    <linkman>
        <name>MLDN</name>
        <email>mldnkf@163</email>
    </linkman>
</addresslist>
要求解析后输出XML的内容。
2.运行所编写的应用程序
启动MyEclipse,建立项目exp5,将编写的程序放入该项目下。运行程序,查看运行结果并进行分析
四、主要仪器设备
笔记本电脑一台    Eclipse软件开发工具  Accesss数据库
五、实验数据记录和处理
Xslxml.java:
package xml;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Xslxml extends HttpServlet {
   
    /**
    * The doGet method of the servlet. <br>
    *
    * This method is called when a form has its tag value method equals to get.
    *
    * @param request the request send by the client to the server
    * @param response the response send by the server to the client
    * @throws ServletException if an error occurred
    * @throws IOException if an error occurred
    */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request,response);
    }
    /**
    * The doPost method of the servlet. <br>
    *
    * This method is called when a form has its tag value method equals to post.
    *
    * @param request the request send by the client to the server
    * @param response the response send by the server to the client
    * @throws ServletException if an error occurred
    * @throws IOException if an error occurred
    */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=GB2312");
        PrintWriter out = Writer();
        out.println("<?xml version=\"1.0\" encoding=\"GBK\"");
        out.println(" standalone=\"no\"?>");
        out.println("<?xml-stylesheet type=\"text/xsl\" href=\"Xslxml.xsl\"?>");
        out.println("<addresslist>");
        out.println("<linkname>");
        out.println("<name>");
        out.println("李兴华");
        out.println("</name>");
        out.println("<br></br>");
        out.println("<id>");
        out.println("001");
        out.println("</id>");
        out.println("</linkname>");
        out.println("</addresslist>");
        out.close();
    }
    /**
    * Initialization of the servlet. <br>
    *
    * @throws ServletException if an error occurs
    */
    public void init() throws ServletException {
        // Put your code here
    }
}
Xslxml.xsl:
<?xml version="1.0" encoding="GBK"?>
<xsl:stylesheet version="1.0" xmlns:xsl="/1999/XSL/Transform">
    <xsl:template match="/">
    <HTML><BODY>
        <xsl:value-of select = "addresslist/linkname/name"/>
        <br></br>
        <xsl:value-of select = "addresslist/linkname/id"/>
    </BODY></HTML>
       
    </xsl:template>
</xsl:stylesheet>
DomXml.java:
package xml;
import org.w3c.dom.*;
import java.io.*;
l.parsers.*;
public class Domxml1 {

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。