Javaweb 实验4 xml

我发现了有些人喜欢静静看博客不聊天呐,

但是ta会点赞。

这样的人呢帅气低调有内涵,

美丽大方很优雅。

说的就是你,

不用再怀疑哦

实验四 XML

目的:

  1. 安装和使用XML的开发环境
  2. 认识XML的不同类型
  3. 掌握XML文档的基本语法
  4. 了解DTD的作用
  5. 掌握DTD的语法
  6. 掌握Schema的语法

实验过程:

  1. 安装XML的编辑器,可以选择以下之一
    1. XMLSpy
    2. VScode,Vscode中安装XML插件
  1. 给定一个XML文档test.xml

<?xml version="1.0"?>

<students>

<student id="001">

<name>tom</name>

<age>24</age>

<major>

<course cid="c1">Python</course>

</major>

<phone>18611111111</phone>

<phone>18622222222</phone>

</student>

<student id="002">

<name>sammy</name>

<age>25</age>

<major>

<course cid="c2">C++</course>

<course cid="c3">computer principle</course>

</major>

<phone>18633333333</phone>

</student>

</students>

  1. 为test.xml定义一个内部的DTD,写出完整的xml文档

代码:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE students [

<!ELEMENT students (student+)>

<!ELEMENT student (name, age, major, phone+)>

<!ATTLIST student id CDATA #REQUIRED>

<!ELEMENT name (#PCDATA)>

<!ELEMENT age (#PCDATA)>

<!ELEMENT major (course+)>

<!ELEMENT course (#PCDATA)>

<!ATTLIST course cid CDATA #REQUIRED>

<!ELEMENT phone (#PCDATA)>

]>

<students>

<student id="001">

<name>tom</name>

<age>24</age>

<major>

<course cid="c1">Python</course>

</major>

<phone>18611111111</phone>

<phone>18622222222</phone>

</student>

<student id="002">

<name>sammy</name>

<age>25</age>

<major>

<course cid="c2">C++</course>

<course cid="c3">computer principle</course>

</major>

<phone>18633333333</phone>

</student>

</students>

  1. 为test.xml定义一个外部的Schema文档,写出schema文档和使用schema文档后的test.xml

Text.xml

复制代码
<?xml version="1.0" encoding="UTF-8"?>
<students xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="test.xsd">
    <student id="001">
        <name>tom</name>
        <age>24</age>
        <major>
            <course cid="c1">Python</course>
        </major>
        <phone>18611111111</phone>
        <phone>18622222222</phone>
    </student>
    <student id="002">
        <name>sammy</name>
        <age>25</age>
        <major>
            <course cid="c2">C++</course>
            <course cid="c3">computer principle</course>
        </major>
        <phone>18633333333</phone>
    </student>
</students>

Text.xsd

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="students">

<xs:complexType>

<xs:sequence>

<xs:element name="student" maxOccurs="unbounded">

<xs:complexType>

<xs:sequence>

<xs:element name="name" type="xs:string"/>

<xs:element name="age" type="xs:integer"/>

<xs:element name="major">

<xs:complexType>

<xs:sequence>

<xs:element name="course" maxOccurs="unbounded">

<xs:complexType>

<xs:simpleContent>

<xs:extension base="xs:string">

<xs:attribute name="cid" type="xs:string" use="required"/>

</xs:extension>

</xs:simpleContent>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="phone" type="xs:string" maxOccurs="unbounded"/>

</xs:sequence>

<xs:attribute name="id" type="xs:string" use="required"/>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

相关推荐
问水っ9 小时前
Qt Creator快速入门 第三版 第17-2章 XML
xml
独断万古他化13 小时前
【MyBatis 深度解析】注解操作与 XML 配置:增删改查全流程实现
xml·java·spring·mybatis
odoo中国21 小时前
如何在 Odoo 19 中加载演示数据
xml·csv·odoo·odoo 19·odoo 演示数据加载
web守墓人3 天前
【前端】ikun-pptx编辑器前瞻问题五:pptx中的xml命名空间
xml·前端
h7ml3 天前
企业微信回调模式解析:从XML到POJO的自定义JAXB编解码器设计
xml·java·企业微信
Full Stack Developme3 天前
达梦(DM8)对 JSON 与 XML 的使用教程
xml·数据库·json
chilavert3184 天前
技术演进中的开发沉思-304计算机原理:XML
xml·计算机原理
程序猿零零漆5 天前
Spring之旅 - 记录学习 Spring 框架的过程和经验(十一)基于XML方式、注解的声明式事务控制、Spring整合Web环境
xml·学习·spring
科雷软件测试5 天前
推荐几个常用的校验yaml、json、xml、md等多种文件格式的在线网站
xml·html·md·yaml
susu10830189116 天前
maven-3.9.12的conf配置settings.xml
xml·java·maven