加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml-schema小案例

发布时间:2020-12-16 06:40:47 所属栏目:百科 来源:网络整理
导读:案例 1 schema 约束 ? xml version = "1.0" encoding = "UTF-8" ? xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema" targetNamespace = "http://www.csdn.net" elementFormDefault = "qualified" xs:element name = '书架' xs:complexType xs:seque

案例1

schema约束

<?xmlversion="1.0"encoding="UTF-8"?>

<xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema"

targetNamespace="http://www.csdn.net"

elementFormDefault="qualified">

<xs:elementname='书架'>

<xs:complexType>

<xs:sequencemaxOccurs="unbounded">

<xs:elementname="书">

<xs:complexType>

<xs:sequence>

<xs:elementname="书名"type="xs:string"/>

<xs:elementname="作者"type="xs:string"/>

<xs:elementname="售价"type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

被约束文件

<?xmlversion="1.0"encoding="UTF-8"?>

<csdn:书架

<!--引用名称空间-->

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

<!--实际指向的名称空间,和文件名-->

xsi:schemaLocation="http://www.csdn.netbook.xsd">

<csdn:书>

<csdn:书名></csdn:书名>

<csdn:作者></csdn:作者>

<csdn:售价></csdn:售价>

</csdn:书>

</csdn:书架>

案例2

<?xmlversion="1.0"encoding="UTF-8"?>

<xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema"

targetNamespace="http://www.example.org/null"xmlns:tns="http://www.example.org/null"

elementFormDefault="qualified">

<xs:elementname="books">

<xs:complexType>

<xs:sequence>

<xs:elementname="book"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

被约束

<?xmlversion="1.0"encoding="UTF-8"?>

<booksxmlns="http://www.example.org/null"

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

xsi:schemaLocation="http://www.example.org/nullnull.xsd">

<bookisbn="xx1"name="java开发"/>

</books>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读