非常感谢孙浩老师的视频和资料。
什么是 XML Schema?
XML Schema 的作用是定义 XML 文档的合法构建模块,类似 DTD。
XML Schema:
XML Schema 是 DTD 的继任者
我们认为 XML Schema 很快会在大部分网络应用程序中取代 DTD。
理由如下:
- XML Schema 可针对未来的需求进行扩展
- XML Schema 更完善,功能更强大
- XML Schema 基于 XML 编写
- XML Schema 支持数据类型 (可以很好的完成对java或者所有对象的修饰并且提供了大量的数据类型)
- XML Schema 支持命名空间 (来支持重复名称相同的元素)
schema.xsd:
<?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/1" xmlns:tns="http://www.example.org/1" elementFormDefault="qualified"> <element name="person"> <complexType> <sequence> <element name="id" type="int"></element> <element name="name" type="string"></element> <element name="birthday" type="date"></element> </sequence> </complexType> </element> </schema>
xml实例一:
<?xml version="1.0" encoding="UTF-8"?> <person xmlns="http://www.example.org/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/1"> <id>1</id> <name>lichen</name> <birthday>1999-11-23</birthday> </person>
xml实例二:
<?xml version="1.0" encoding="UTF-8"?> <person xmlns="http://www.example.org/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="1.xsd"> <id>2</id> <name>chengwei</name> <birthday>1969-7-8</birthday> </person>
实例一,二都可用schema验证。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。