zoukankan      html  css  js  c++  java
  • 个人记录贴——XML实验报告

    本XML环境为WIN10,其余环境的配置需自行调整,生成文件的方式为右键新建TXT文件,然后将后缀名改成对应的dtdxmlxsd等,如果电脑内装有Atom或是VScode编辑器可以选择创建最新版。本实验内容纯个人手写,非标准答案,如有错误还烦请指出,我会尽量在第一时间,更正。

    实验一 XML基础与XML编辑器的使用

    一.实验目的

    1、掌握XML1.0的标准及内容

    2、掌握XML的基本格式

    3、掌握XML SPY或VSCode的基本使用方法

    二.实验内容

    1、使用XML Spy或记事本等文本编辑器编辑如下XML文档,并保存文件名为code1_1.xml,然后在IE中浏览。

     

    <?xml version="1.0" encoding="gb2312" ?>

    <orders>

      <order>

        <customerID>c0500069</customerID>

        <order_date>20050517</order_date>

        <order_status>pending</order_status>

        <items>

          <item>

           <bookID>001</bookID>

           <quantity>10</quantity>

            <item_status>pending</item_status>

          </item>

        </items>

      </order>

      <order>

        <customerID>c500701</customerID>

        <order_date>20050712</order_date>

        <order_status>pending</order_status>

        <items>

          <item>

           <bookID>002</bookID>

           <quantity>30</quantity>

            <item_status>pending</item_status>

          </item>

          <item>

           <bookID>003</bookID>

           <quantity>20</quantity>

            <item_status>pending</item_status>

          </item>

        </items>

      </order>

    </orders>

     

     文件格式:code1_1.xml

    1 <?xml version="1.0" encoding="gb2312" ?> 2 <orders> 3 <order> 4 <customerID>c0500069</customerID> 5 <order_date>20050517</order_date> 6 <order_status>pending</order_status> 7 <items> 8 <item> 9 <bookID>001</bookID> 10 <quantity>10</quantity> 11 <item_status>pending</item_status> 12 </item> 13 </items> 14 </order> 15 <order> 16 <customerID>c500701</customerID> 17 <order_date>20050712</order_date> 18 <order_status>pending</order_status> 19 <items> 20 <item> 21 <bookID>002</bookID> 22 <quantity>30</quantity> 23 <item_status>pending</item_status> 24 </item> 25 <item> 26 <bookID>003</bookID> 27 <quantity>20</quantity> 28 <item_status>pending</item_status> 29 </item> 30 </items> 31 </order> 32 </orders>

    2、下面是一个网上购物订单,将它写成XML格式,并用XML SPY或VSCode编辑,保存为code1_2.xml。

    顾客编号:X00349827,订单号:DD934809,订货时间:2004-05-17;

    付款方式:邮局汇款,通讯地址:xxx市xxx路xxx号,邮编:123456;

    汇款地址:yyy市yyy路yyy号,收款人xxxx书店;

    定书号:001,书名:AAA,数量:1,价格:34.00;

    定书号:002,书名:BBB,数量:1,价格:29.00;

    定书号:003,书名:CCC,数量:1,价格:41.00。

     文件格式:code1_2.xml   // 注意下,XML0标签内是可以使用中文的,或者说是非ASCII码的字符,不过encoding=""  要对应好相应的编码,否则乱码不通过

    1
    <?xml version="1.0" encoding="UTF-8" ?> 2 <顾客编号> 3 <顾客编号>X00349827</顾客编号> 4 <订单号>DD934809</订单号> 5 <订货时间>2004-05-17</订货时间> 6 <付款方式>邮局汇款</付款方式> 7 <通讯地址>xxx市xxx路xxx号</通讯地址> 8 <邮编>123456</邮编> 9 <汇款地址>yyy市yyy路yyy号,收款人xxxx书店;</汇款地址> 10 <> 11 <订书号>001</订书号> 12 <书名>AAA</书名> 13 <数量>1</数量> 14 <价格>34.00</价格> 15 </> 16 <> 17 <订书号>002</订书号> 18 <书名>BBB</书名> 19 <数量>1</数量> 20 <价格>29.00</价格> 21 </> 22 <> 23 <订书号>003</订书号> 24 <书名>CCC</书名> 25 <数量>1</数量> 26 <价格>41.00</价格> 27 </> 28 </顾客编号>

     

    实验二 XML DTD 与XML Schema的使用

    一.实验目的

    1、掌握DTD的定义、引用

    2、掌握DTD的验证

    3、掌握XML Schema的定义、引用

    4、掌握XML Schema的验证

    5、了解XML Schema中名称空间的使用

    二.实验内容

    1、如图所示,为其设计XML及其对应的DTD,分别命名为code2_1.xml、code2_1.dtd。

     文件格式:code2_1.xml   // 注意这里的SYSTEM "code2_1.dtd"  是直接链接,win10要保持在同一个文件目录下,mac、linux不清楚。

    1
    <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE 博物馆 SYSTEM "code2_1.dtd"> 3 <博物馆> 4 <油画> 5 <作者>1</作者> 6 <尺寸>1</尺寸> 7 <成画时间>1</成画时间> 8 </油画> 9 <雕塑> 10 <作者>1</作者> 11 <质量>1</质量> 12 </雕塑> 13 <古币> 14 <币值>1</币值> 15 <使用年代>1</使用年代> 16 </古币> 17 </博物馆>
     文件格式:code2_1.dtd

    1
    <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE 博物馆[ 3 <!ELEMENT 博物馆 (油画*,雕塑*,古币*)> 4 <!ELEMENT 油画 (作者,尺寸,成画时间)> 5 <!ELEMENT 作者 (#PCDATA)> 6 <!ELEMENT 尺寸 (#PCDATA)> 7 <!ELEMENT 成画时间 (#PCDATA)> 8 <!ELEMENT 雕塑 (作者,质量)> 9 <!ELEMENT 作者 (#PCDATA)> 10 <!ELEMENT 质量 (#PCDATA)> 11 <!ELEMENT 古币 (币值,使用年代)> 12 <!ELEMENT 币值 (#PCDATA)> 13 <!ELEMENT 使用年代 (#PCDATA)> 14 ]>

    2、在一个XML文档中,需要用到一个article的结点,这个结点结构如下:

     

    <article>

        <HeadLine section="business">

          <MainHead>Main headline goes here</MainHead>

          <SubHead>A subheadline goes here</SubHead>

        </HeadLine>

        <ByLine>

          <Author>John Doe</Author>

          <title>Reporter</title>

        </ByLine>

            <DateLine>April 30, 2005</Dateline>

           <body>Content of story goes here…</body>

            <stats>  

            <submitted>2005-03-02</submitted>

            <wordCount>1523</wordCount>

        </stats>

    </article>

     

    (1)请在分别定义HeadLine、ByLine、DateLine、stats结点的数据类型基础上,再定义article的复杂数据类型。

    (2)若以上程序段多篇文章(articles),XML保存为code2_2.xml请为其建立完整的XML Schema文件,保存文件名为code2_2.xsd。

     文件格式:code2_2.xml 

    1
    <?xml version="1.0" encoding="UTF-8" ?> 2 <book xmlns="http://www.w3school.com.cn" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="code2_2.xsd"> 5 <article> 6 <HeadLine section="business"> 7 <MainHead>Main headline goes here</MainHead> 8 <SubHead>A subheadline goes here</SubHead> 9 </HeadLine> 10 <ByLine> 11 <Author>John Doe</Author> 12 <title>Reporter</title> 13 </ByLine> 14 <DateLine>April 30, 2005</DateLine> 15 <body>Content of story goes here…</body> 16 <stats> 17 <submitted>2005-03-02</submitted> 18 <wordCount>1523</wordCount> 19 </stats> 20 </article> 21 </book>
      文件格式:code2_2.xsd 

    1
    <?xml version="1.0"?> 2 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 3 targetNamespace="http://www.w3school.com.cn" 4 xmlns="http://www.w3school.com.cn" 5 elementFormDefault="qualified"> 6 7 <xs:element name="book" type="book"/> 8 <xs:complexType name="book" > 9 <xs:sequence> 10 <xs:element name="article" type="article"/> 11 </xs:sequence> 12 </xs:complexType> 13 <xs:complexType name="article"> 14 <xs:sequence> 15 <xs:element name="HeadLine" type="HeadLine"/> 16 <xs:element name="ByLine" type="ByLine"/> 17 <xs:element name="DateLine" type="xs:string"/> 18 <xs:element name="body" type="xs:string"/> 19 <xs:element name="stats" type="stats"/> 20 </xs:sequence> 21 </xs:complexType> 22 <xs:complexType name="HeadLine"> 23 <xs:sequence> 24 <xs:element name="MainHead" type="xs:string"/> 25 <xs:element name="SubHead" type="xs:string"/> 26 </xs:sequence> 27 </xs:complexType> 28 <xs:complexType name="ByLine"> 29 <xs:sequence> 30 <xs:element name="Author" type="xs:string"/> 31 <xs:element name="title" type="xs:string"/> 32 </xs:sequence> 33 </xs:complexType> 34 <xs:complexType name="stats"> 35 <xs:sequence> 36 <xs:element name="submitted" type="xs:date"/> 37 <xs:element name="wordCount" type="xs:decimal"/> 38 </xs:sequence> 39 </xs:complexType> 40 41 </xs:schema>

    3、为 以下XML 文档设计对应的XML Schema文件,保存文件名为code2_3.xsd,XML文件保存为code2_3.xml

    <?xml version="1.0" encoding="ISO-8859-1"?>

    <shiporder orderid="889923"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:noNamespaceSchemaLocation="shiporder.xsd">

     <orderperson>George Bush</orderperson>

     <shipto>

      <name>John Adams</name>

      <address>Oxford Street</address>

      <city>London</city>

      <country>UK</country>

     </shipto>

     <item>

      <title>Empire Burlesque</title>

      <note>Special Edition</note>

      <quantity>1</quantity>

      <price>10.90</price>

     </item>

     <item>

      <title>Hide your heart</title>

      <quantity>1</quantity>

      <price>9.90</price>

     </item>

    </shiporder>

    
    
     文件格式:code2_3.xml 

    1
    <?xml version="1.0" encoding="ISO-8859-1"?> 2 <shiporder orderid="889923" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:noNamespaceSchemaLocation="code2_3.xsd"> 5 <orderperson>George Bush</orderperson> 6 <shipto> 7 <name>John Adams</name> 8 <address>Oxford Street</address> 9 <city>London</city> 10 <country>UK</country> 11 </shipto> 12 <item> 13 <title>Empire Burlesque</title> 14 <note>Special Edition</note> 15 <quantity>1</quantity> 16 <price>10.90</price> 17 </item> 18 <item> 19 <title>Hide your heart</title> 20 <quantity>1</quantity> 21 <price>9.90</price> 22 </item> 23 </shiporder>
     文件格式:code2_3.xsd

    1
    <?xml version="1.0"?> 2 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 3 targetNamespace="http://www.w3school.com.cn" 4 xmlns="http://www.w3school.com.cn" 5 elementFormDefault="qualified"> 6 7 <xs:element name="shiporder" type="shiporder"/> 8 <xs:complexType name="book" > 9 <xs:sequence> 10 <xs:element name="orderperson" type="xs:string"/> 11 <xs:element name="shipto" type="shipto"/> 12 <xs:element name="item" type="item"/> 13 </xs:sequence> 14 </xs:complexType> 15 <xs:complexType name="orderperson"> 16 <xs:sequence> 17 <xs:element name="name" type="xs:string"/> 18 <xs:element name="address" type="xs:string"/> 19 <xs:element name="city" type="xs:string"/> 20 <xs:element name="country" type="xs:string"/> 21 </xs:sequence> 22 </xs:complexType> 23 <xs:complexType name="shipto"> 24 <xs:sequence> 25 <xs:element name="title" type="xs:string"/> 26 <xs:element name="note" type="xs:string"/> 27 <xs:element name="quantity" type="xs:integer"/> 28 <xs:element name="price" type="xs:float"/> 29 </xs:sequence> 30 </xs:complexType> 31 </xs:schema>

    实验三 CSS 与XSLT的应用

    一.实验目的

    1、掌握XML 和 CSS显示的方法

    2、了解XSLT使用方法

    3、体会两者的区别。

    二.实验内容

    1、按要求完成案例(如下图),其功能是实现后台管理的界面显示。

    (1)编辑 XML文档,如code3_1.xml。

    (2)编写对应的 XSLT 样式表,如code3_1.xsl。

    (3)显示这个由 XSLT 样式表格式化的界面。

    文件格式:code3_1.xsl

    <?
    xml version="1.0" encoding="UTF-8" ?> <?xml-stylesheet type="text/xsl" href="code3_1.xsl"?> <XXX课程管理系统> <body> <header> <h1>XXX课程管理系统</h1> </header> <nav> <br/> <hr/><center><a herf="">课程管理</a></center><hr/><br/><br/> <hr/><center><a herf="*">学生管理</a></center><hr/><br/><br/> <hr/><center><a herf="*">退出系统</a></center><hr/><br/> <br/> </nav> <article> 您的位置:首页/Dashboard <hr/> <br/> 正文内容 </article> <footer> <hr/> <p>KMUST CopyRight2016</p> </footer> </body> </XXX课程管理系统>
      文件格式:code3_1.xml

    1
    <?xml version="1.0" encoding="UTF-8"?> 2 3 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 4 5 <xsl:template match="/"> 6 <html> 7 <style> 8 * {margin:0; padding:0;} 9 body { 10 font-family:helvetica, arial, sans-serif; 11 } 12 header { 13 background:rgb(81, 108, 158); 14 height: 75px; 15 } 16 header h1 { 17 font-family:'Droid Sans'; 18 font-weight:300; 19 font-size:3em; 20 letter-spacing:-.05em; 21 color:#fff; 22 padding:0 0 5px 10px; 23 } 24 25 26 nav { 27 float:left; 28 display:table-cell; 29 150px; 30 height: 500px; 31 background:#b5eeff; 32 } 33 34 nav hr {color:#ffffff;} 35 36 nav a { 37 font-family:'Open Sans Condensed'; 38 font-weight:700; 39 font-size:1em; 40 color:#000000; 41 } 42 article { 43 weight:2000px; 44 background:#ffffff; 45 padding:5px 20px; 46 } 47 48 article h1 { 49 font-family:'Droid Sans'; 50 font-weight:700; 51 font-size:1.2em; 52 letter-spacing:-.05em; 53 color:#rgb(0.0.0); 54 } 55 article p { 56 font-family:'Open Sans Condensed'; 57 font-weight:300; 58 font-size:1em; 59 color:#000; 60 } 61 62 aside p { 63 font-family:'Open Sans Condensed'; 64 font-weight:700; 65 font-size:.85em; 66 line-height:1.2em; 67 color:#fff; 68 } 69 footer { 70 height:20px; 71 clear:both; 72 background:rgb(255, 255, 255); 73 text-align:center; 74 padding:5px 0px; 75 } 76 77 footer hr {color:rgb(240, 240, 240 );} 78 footer p { 79 font-family:'Open Sans'; 80 font-weight:700; 81 font-size:.65em; 82 color:rgb(0, 0, 0); 83 } 84 </style> 85 <body> 86 <header> 87 <h1>XXX课程管理系统</h1> 88 </header> 89 <nav> 90 <br/> 91 <hr/><center><a herf="">课程管理</a></center><hr/><br/><br/> 92 <hr/><center><a herf="*">学生管理</a></center><hr/><br/><br/> 93 <hr/><center><a herf="*">退出系统</a></center><hr/><br/><br/> 94 </nav> 95 <article> 96 <h1>您的位置:首页/Dashboard</h1> 97 <hr/> 98 <br/> 99 <p>正文内容</p> 100 </article> 101 <footer> 102 <hr/> 103 <p>KMUST CopyRight2016</p> 104 </footer> 105 </body> 106 </html> 107 </xsl:template> 108 109 </xsl:stylesheet>

    实验四 XML与Java

    一.实验目的

    1、掌握Java使用DOM加载XML的方法;

    2、掌握使用DOM创建XML文件的方法;

    3、学会转换XML文件为HTML的方法。

    二.实验内容

    1、示例6.1,使用Java语言解析XML文件,创建XML节点。

    2、示例5.12。使用Java语言转换XML文件为HTML的方法。

    本次实验依照的是一本已经(绝版?)的书籍出题。嘛,知识并没有过时的样子,只是这本书已经下架买不到了。所以与示例相关的内容就略过了。

    下面我以个人看法来谈谈XML与Java

    1.教的啥,XML就应该在eclipse这种环境下去调整好嘛?为什么要单独拿出来教啊。

    2.推荐去哪种项目速成班:(举例:黑马人工智能)去了解XML在整个工程中的作用,以及对应的编辑器环境,实在不推荐抛开数据库与数据结构单独学。

  • 相关阅读:
    Spring+SpringMVC+MyBatis深入学习及搭建(一)——MyBatis的基础知识
    单例模式
    JVM的内存区域划分以及垃圾回收机制详解
    线上出现OutOfMemoryError的一次解决问题记录
    MYSQL针对于行多个字段转成多行的处理
    MYSQL 在insert时出现死锁的情况
    idea下载
    LTS用户文档
    HMS06. 编译构件相关
    HMS05. 与IDE使用相关的杂顶内容
  • 原文地址:https://www.cnblogs.com/Kxia/p/10646080.html
Copyright © 2011-2022 走看看