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

xml-schema仅含有文本及案例

发布时间:2020-12-16 06:40:45 所属栏目:百科 来源:网络整理
导读:!--Schema- 仅含有文本 -- 案例 ?xmlversion="1.0"encoding="UTF-8"? xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/text" xmlns:tns="http://www.example.org/text" elementFormDefault="qualified" !--x

<!--Schema-仅含有文本-->

案例

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

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

targetNamespace="http://www.example.org/text"

xmlns:tns="http://www.example.org/text"

elementFormDefault="qualified">

<!--xmlschema仅含有文本-->

<xs:elementname="books">

<xs:complexType>

<xs:sequence>

<xs:elementname="book">

<xs:complexType>

<xs:sequence>

<xs:elementname="name">

<!--简单的类型即可-->

<xs:simpleType>

<xs:restrictionbase="xs:string">

<xs:patternvalue="[a-z]{9}"></xs:pattern>

</xs:restriction>

</xs:simpleType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

被约束文件

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

<booksxmlns="http://www.example.org/text"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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

<book>

<name>aaaaaaaaa</name>

</book>

</books>

案例2

<!--混合类型-无序->

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

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

targetNamespace="http://www.example.org/text"

xmlns:tns="http://www.example.org/text"

elementFormDefault="qualified">

<!--xmlschema仅含有文本-->

<xs:elementname="books">

<xs:complexType>

<xs:sequence>

<xs:elementname="book">

<!--mixed=true代表是混合类型的-->

<xs:complexTypemixed="true">

<!--代表无序-->

<xs:all>

<xs:elementname="name"maxOccurs="1">

<!--简单的类型即可-->

<xs:simpleType>

<xs:restrictionbase="xs:string">

<xs:patternvalue="[a-z]{9}"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

<xs:elementname="price"type="xs:double"/>

</xs:all>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

无序

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

<booksxmlns="http://www.example.org/text"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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

<book>

<!--all代表的是无序的-->

<price>12.9</price>

<name>xxxxxxxxx</name>

</book>

</books>

案例3

<!--互斥-->

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

targetNamespace="http://www.example.org/text"

xmlns:tns="http://www.example.org/text"

elementFormDefault="qualified">

<!--xmlschema仅含有文本-->

<xs:elementname="books">

<xs:complexType>

<xs:sequence>

<xs:elementname="book">

<!--mixed=true代表是混合类型的-->

<xs:complexTypemixed="true">

<!--choice代表的是互斥的-->

<xs:choice>

<xs:elementname="name"maxOccurs="1">

<!--简单的类型即可-->

<xs:simpleType>

<xs:restrictionbase="xs:string">

<xs:patternvalue="[a-z]{9}"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

<xs:elementname="price"type="xs:double"/>

</xs:choice>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

被约束文件

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

<booksxmlns="http://www.example.org/text"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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

<book>

<!--choice代表的是互斥的-->

<price>12.9</price>

</book>

</books>

案例4

<!--schema--->

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

targetNamespace="http://www.example.org/text"

xmlns:tns="http://www.example.org/text"

elementFormDefault="qualified">

<!--xmlschema仅含有文本-->

<xs:elementname="books">

<xs:complexType>

<xs:sequence>

<xs:elementname="book">

<!--mixed=true代表是混合类型的-->

<xs:complexTypemixed="true">

<!--sequence代表的是有序的-->

<xs:sequence>

<xs:elementname="name"maxOccurs="5">

<!--简单的类型即可-->

<xs:simpleType>

<xs:restrictionbase="xs:string">

<xs:patternvalue="[a-z]{9}"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

<xs:elementname="price"type="xs:double"minOccurs="2"maxOccurs="unbounded"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

被约束文件

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

<booksxmlns="http://www.example.org/text"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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

<book>

<!--sequence代表的是有序的-->

<name>xxxxxxxxx</name>

<name>xxxxxxxxx</name>

<name>xxxxxxxxx</name>

<name>xxxxxxxxx</name>

<name>xxxxxxxxx</name>

<price>12.9</price>

<price>12.9</price>

<price>12.9</price>

<price>12.9</price>

<price>12.9</price>

<price>12.9</price>

<price>12.9</price>

<price>12.9</price>

<price>12.9</price>

<price>12.9</price>

</book>

</books>

案例5

<!--定义组-有序单个->

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

targetNamespace="http://www.example.org/text"

xmlns:tns="http://www.example.org/text"

xmlns="http://www.example.org/text"

elementFormDefault="qualified">

<!--定义组-->

<xs:groupname="bookGroup">

<xs:sequence>

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

<xs:elementname="price"type="xs:double"/>

<xs:elementname="cdata"type="xs:date"/>

</xs:sequence>

</xs:group>

<xs:elementname="books">

<xs:complexType>

<xs:sequence>

<xs:elementname="book">

<xs:complexType>

<xs:sequence>

<!--引用组-->

<xs:groupref="bookGroup"/>

<xs:elementname="author"type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

被约束文件

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

<booksxmlns="http://www.example.org/text"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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

<book>

<!--group代表的是有序的-->

<name>xxxxxxxxx</name>

<price>12.9</price>

<cdata>2010-10-10</cdata>

<author>chenhj</author>

</book>

</books>

案例6

<!--定义组-无序、多个->

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

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

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

xmlns="http://www.example.org/text"elementFormDefault="qualified">

<!--定义组-->

<xs:groupname="bookGroup">

<xs:choice>

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

<xs:elementname="price"type="xs:string"/>

<xs:elementname="cdata"type="xs:string"/>

</xs:choice>

</xs:group>

<xs:elementname="books">

<xs:complexType>

<xs:all>

<xs:elementname="book">

<xs:complexType>

<xs:sequence>

<!--引用组-->

<xs:groupref="bookGroup"maxOccurs="unbounded"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:all>

</xs:complexType>

</xs:element>

</xs:schema>

被约束文件

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

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

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

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

<book>

<!--group代表的是有序的-->

<!--无序,多次-->

<name>xxxxxxxxx</name>

<cdata>2</cdata>

<price>2</price>

<price>2</price>

<price>2</price>

<price>2</price>

<price>2</price>

<price>2</price>

<price>2</price>

</book>

</books>

(编辑:李大同)

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

    推荐文章
      热点阅读