XML&Jsoup解析器【最详细教程】(1)

tom

18

male

  • dtd约束文档的缺点
  1. 不能限定内容

  2. 语法结构:

DTD的语法与XMl不同,使用DOM,XPath,XSL无法处理,为自动化文档处理带来不便

  1. 数据类型

DTD数据类型不能自由扩充,不利于XML数据交换场合验证

3.文档结构

DTD中,所有元素、属性都是全局的, 无法声明仅与上下文位置相关的元素或属性

  1. 名称空间

DTD中没有名称空间的概念,不直接支持名称空间

2、Schema约束文档【主流】

  • Schema:

  • 引入:

1.填写xml文档的根元素

2.引入xsi前缀. xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

3.引入xsd文件命名空间. xsi:schemaLocation=“http://www.itcast.cn/xml student.xsd”

4.为每一个xsd约束声明一个前缀,作为标识 xmlns=“http://www.itcast.cn/xml”

<students xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xmlns=“http://www.itcast.cn/xml”

xsi:schemaLocation=“http://www.itcast.cn/xml student.xsd”>

  • student.xsd
<?xml version="1.0"?>

<xsd:schema xmlns=“http://www.itcast.cn/xml”

xmlns:xsd=“http://www.w3.org/2001/XMLSchema”

targetNamespace=“http://www.itcast.cn/xml” elementFormDefault=“qualified”>

<xsd:element name=“students” type=“studentsType”/>

<xsd:complexType name=“studentsType”>

xsd:sequence

<xsd:element name=“student” type=“studentType” minOccurs=“0” maxOccurs=“unbounded”/>

</xsd:sequence>

</xsd:complexType>

<xsd:complexType name=“studentType”>

xsd:sequence

<xsd:element name=“name” type=“xsd:string”/>

<xsd:element name=“age” type=“ageType” />

<xsd:element name=“sex” type=“sexType” />

</xsd:sequence>

<xsd:attribute name=“number” type=“numberType” use=“required”/>

</xsd:complexType>

<xsd:simpleType name=“sexType”>

<xsd:restriction base=“xsd:string”>

<xsd:enumeration value=“male”/>

<xsd:enumeration value=“female”/>

</xsd:restriction>

</xsd:simpleType>

<xsd:simpleType name=“ageType”>

<xsd:restriction base=“xsd:integer”>

<xsd:minInclusive value=“0”/>

<xsd:maxInclusive value=“256”/>

</xsd:restriction>

</xsd:simpleType>

<xsd:simpleType name=“numberType”>

<xsd:restriction base=“xsd:string”>

<xsd:pattern value=“heima_\d{4}”/>

</xsd:restriction>

</xsd:simpleType>

</xsd:schema>

  • xml导入写框架人写的约束
<?xml version="1.0" encoding="UTF-8" ?>

<students xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xmlns=“http://www.itcast.cn/xml”

xsi:schemaLocation=“http://www.itcast.cn/xml student.xsd”

tom

18

male

  • Springmvc的xml详解
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=“http://www.springframework.org/schema/beans”

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

xmlns:context=“http://www.springframework.org/schema/context”

xmlns:mvc

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值