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>

相关推荐
鹏晨互联19 分钟前
《深入理解 Compose 中的 matchParentSize 与 fillMaxSize —— 从 XML 到 Compose 的对比解析》
xml
小短腿的代码世界1 小时前
Qt SVG渲染管线全解析:从XML解析到像素绘制的完整架构设计与性能优化实战
xml·qt·性能优化
HMS工业网络1 天前
技术干货:EtherCAT设备ESI(XML)文件中的CompleteAccess关键字有什么作用
xml·运维·服务器
鹏晨互联2 天前
【Compose vs XML:边框内外间距的实现对比】
android·xml
鹏晨互联3 天前
Jetpack Compose vs XML:fillMaxSize、fillMaxHeight、fillMaxWidth 全面对比
android·xml
如果'\'真能转义说4 天前
OOXML 文档格式剖析:哈希、ZIP结构与识别
xml·算法·c#·哈希算法
ZC跨境爬虫5 天前
跟着 MDN 学 HTML day_34:(深入XML 中的 CDATASection 接口)
xml·前端·html·html5·媒体
hmywillstronger5 天前
【Python】从SAP2000 XML截面库提取数据到Excel
xml·python·excel
Boop_wu5 天前
[Mybatis] XML 方式实现 MP 自定义 SQL + 条件构造器
xml·sql·mybatis