您好,欢迎来到微智科技网。
搜索
您的当前位置:首页太原理工大学硬件实验5

太原理工大学硬件实验5

来源:微智科技网
课程名称:

实验项目:

实验地点:

专业班级:

学生姓名:指导教师:

本科实验报告

Web系统与技术 xml操作 致远楼301 软件工程1222 学号:2012005612 王兆晖 师锋洋

2015 年1 月17日

一、实验目的

掌握XML的语法,学会XML操作。

二、实验要求

1.完成实验 2.书写实验报告书

三、实验内容

1、编写程序。

1)程序:课本P290习题11.8。 要求:对应的XML文档内容为:

李兴华 001

要求:李兴华和001之间间隔1行。 2)程序:课本P290习题11.10。

李兴华

mldnqa@163.com

MLDN

mldnkf@163.com

要求解析后输出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.
*

* 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.
*

* 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 = response.getWriter();

out.println(\"\");

out.println(\"\"); out.println(\"\"); out.println(\"\"); out.println(\"\"); out.println(\"李兴华\"); out.println(\"\"); out.println(\"

\"); out.println(\"\"); out.println(\"001\"); out.println(\"\");

out.println(\"\"); out.println(\"\"); out.close();

}

/**

* Initialization of the servlet.
*

* @throws ServletException if an error occurs */

public void init() throws ServletException { // Put your code here }

Xslxml.xsl: xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">



DomXml.java: package xml;

import org.w3c.dom.*; import java.io.*;

import javax.xml.parsers.*;

public class Domxml1 {

public static void main(String args[]){ try{ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new File(\"Domxml1.xml\")); document.normalize(); Element root = document.getDocumentElement(); String rootName = root.getNodeName(); System.out.print(\"XML文件根节点的名字:\"+rootName); NodeList nodelist = root.getChildNodes(); GetElement(nodelist);

}

} catch(Exception e){ System.out.println(e); } }

public static void GetElement(NodeList nodelist){ int size = nodelist.getLength(); for(int i = 0;i < size;i++){ Node cnode = nodelist.item(i); if(cnode.getNodeType() == Node.TEXT_NODE){ Text textNode = (Text)cnode; String content = textNode.getWholeText(); System.out.print(content); } if(cnode.getNodeType() == Node.ELEMENT_NODE){ Element elementNode = (Element)cnode; String name = elementNode.getNodeName(); System.out.print(name+\": \"); NodeList nodelist1 = elementNode.getChildNodes(); GetElement(nodelist1); } } }

六、 实验结果与分析

七、讨论、心得

掌握了使用Jsp+servlet进行动态的产检XML文件,并让其显示为XSL样式。同时也熟悉了DOM解析XML的过程。

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务