xml学习总结(三)
生活随笔
收集整理的這篇文章主要介紹了
xml学习总结(三)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
復(fù)雜Schema
擴(kuò)展包含簡(jiǎn)單內(nèi)容的復(fù)雜類(lèi)型
?
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"><!-- 定義一個(gè)book_Type類(lèi)型 --><xs:complexType name="book_Type"><xs:simpleContent><!-- 從token類(lèi)型派生出book_Type類(lèi)型 --><xs:extension base="xs:token"><!-- 增加一個(gè)name屬性 --><xs:attribute name="name" type="xs:token" use="required"/><!-- 增加一個(gè)isbn屬性 --> <xs:attribute name="isbn" use="required"><!-- 使用simpleType子元素定義isbn屬性的類(lèi)型 --><xs:simpleType><xs:restriction base="xs:int"><xs:totalDigits value="8"/></xs:restriction></xs:simpleType></xs:attribute></xs:extension></xs:simpleContent></xs:complexType><!-- 定義一個(gè)extended_book_Type類(lèi)型 --><xs:complexType name="extended_book_Type"><xs:simpleContent><!-- 從book_Type類(lèi)型派生出extended_book_Type類(lèi)型 --><xs:extension base="book_Type"><!-- 增加price屬性 --><xs:attribute name="price" use="required"><!-- 使用simpleType子元素定義price屬性的類(lèi)型 --><xs:simpleType><xs:restriction base="xs:decimal"><xs:maxExclusive value="100"/><xs:minExclusive value="0"/><xs:fractionDigits value="2"/></xs:restriction></xs:simpleType></xs:attribute></xs:extension></xs:simpleContent></xs:complexType><!-- 定義book元素,其類(lèi)型是extended_book_Type --><xs:element name="book" type="extended_book_Type"/> </xs:schema>?
限制包含簡(jiǎn)單類(lèi)型的復(fù)雜類(lèi)型
?
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"elementFormDefault="qualified" attributeFormDefault="unqualified"><!-- 定義一個(gè)book_Type類(lèi)型 --><xs:complexType name="book_Type"><xs:simpleContent><xs:extension base="xs:token"><xs:attribute name="name" type="xs:token" use="required"/><xs:attribute name="isbn"><!-- 使用simpleType子元素定義isbn屬性的類(lèi)型 --><xs:simpleType><xs:restriction base="xs:int"><xs:totalDigits value="8"/></xs:restriction></xs:simpleType></xs:attribute></xs:extension></xs:simpleContent></xs:complexType><!-- 定義一個(gè)restricted_book_Type類(lèi)型 --><xs:complexType name="restricted_book_Type"><xs:simpleContent><xs:restriction base="book_Type"><!-- 定義該元素的內(nèi)容只能是如下枚舉值之一 --><xs:enumeration value="瘋狂Java體系"/><xs:enumeration value="瘋狂Java實(shí)訓(xùn)教程"/> <xs:attribute name="name" use="required"><!-- 使用simpleType重新限定name屬性的類(lèi)型 --><xs:simpleType><xs:restriction base="xs:token"><xs:maxLength value="14"/><xs:minLength value="4"/></xs:restriction></xs:simpleType></xs:attribute><!-- 刪除原來(lái)的isbn屬性 --><xs:attribute name="isbn" use="prohibited"/></xs:restriction></xs:simpleContent></xs:complexType><!-- 定義book元素,其類(lèi)型是restricted_book_Type --><xs:element name="book" type="restricted_book_Type"/> </xs:schema>?
限制包含子元素的類(lèi)型
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"elementFormDefault="qualified" attributeFormDefault="unqualified"><!-- 定義一個(gè)book_Type類(lèi)型,該類(lèi)型下包含2個(gè)有序子元素 --><xs:complexType name="book_Type"><!-- 使用sequence定義2個(gè)子元素 --><xs:sequence><xs:element name="name" type="xs:token"/><!-- 如果派生類(lèi)型想刪除如下子元素,必須指定minOccurs="0" --><xs:element name="price" type="xs:decimal" minOccurs="0"/></xs:sequence><!-- 為該類(lèi)型定義2個(gè)屬性 --> <xs:attribute name="isbn" type="xs:int"/><xs:attribute name="publish-date" type="xs:date"/></xs:complexType><!-- 定義restrict_book_Type類(lèi)型 --><xs:complexType name="restrict_book_Type"><xs:complexContent><!-- 通過(guò)限制book_Type類(lèi)型派生新類(lèi)型 --><xs:restriction base="book_Type"><xs:sequence><!-- 為name元素的類(lèi)型增加進(jìn)一步約束 --><xs:element name="name"><xs:simpleType><xs:restriction base="xs:token"><xs:maxLength value="20"/><xs:minLength value="4"/></xs:restriction></xs:simpleType></xs:element><!-- 不再定義price元素,即可認(rèn)為刪除了該元素 --></xs:sequence><!-- 為publish-date屬性的類(lèi)型增加進(jìn)一步約束 --><xs:attribute name="publish-date"><xs:simpleType><xs:restriction base="xs:date"><xs:maxExclusive value="2009-05-12"/><xs:minExclusive value="2007-05-12"/></xs:restriction></xs:simpleType> </xs:attribute><!-- 刪除isbn屬性 --><xs:attribute name="isbn" use="prohibited"/></xs:restriction></xs:complexContent></xs:complexType> <xs:element name="book" type="restrict_book_Type"/> </xs:schema>擴(kuò)展包含子元素的類(lèi)型
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"elementFormDefault="qualified" attributeFormDefault="unqualified"><!-- 定義一個(gè)book_Type類(lèi)型,該類(lèi)型下包含2個(gè)有序子元素 --><xs:complexType name="book_Type"><!-- 使用sequence定義2個(gè)子元素 --><xs:sequence><xs:element name="name" type="xs:token"/><xs:element name="price" type="xs:decimal"/></xs:sequence><!-- 為該類(lèi)型定義2個(gè)屬性 --> <xs:attribute name="isbn" type="xs:int"/><xs:attribute name="publish-date" type="xs:date"/></xs:complexType><!-- 定義extend_book_Type類(lèi)型 --><xs:complexType name="extend_book_Type"><xs:complexContent><!-- 通過(guò)擴(kuò)展book_Type類(lèi)型派生新類(lèi)型 --><xs:extension base="book_Type"><xs:sequence><!-- 新增定義2個(gè)子元素 --><xs:element name="type" type="xs:token"/><xs:element name="targetMarket" type="xs:token"/></xs:sequence><!-- 新增一個(gè)publish-house屬性 --><xs:attribute name="publish-house" type="xs:token"/></xs:extension></xs:complexContent></xs:complexType> <xs:element name="book" type="extend_book_Type"/> </xs:schema>?限制混合內(nèi)容類(lèi)型
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"elementFormDefault="qualified" attributeFormDefault="unqualified"><!-- 定義一個(gè)book_Type類(lèi)型,該類(lèi)型下包含2個(gè)有序子元素,指定它是混合內(nèi)容類(lèi)型 --><xs:complexType name="book_Type" mixed="true"><!-- 使用sequence定義2個(gè)子元素 --><xs:sequence><xs:element name="name" type="xs:token"/><!-- 如果派生類(lèi)型想刪除如下子元素,必須指定minOccurs="0" --><xs:element name="price" type="xs:decimal" minOccurs="0"/></xs:sequence><!-- 為該類(lèi)型定義2個(gè)屬性 --> <xs:attribute name="isbn" type="xs:int"/><xs:attribute name="publish-date" type="xs:date"/></xs:complexType> <!-- 定義mixed_book_Type類(lèi)型,依然是混合內(nèi)容類(lèi)型 --><xs:complexType name="mixed_book_Type" mixed="true"><xs:complexContent><!-- 通過(guò)限制book_Type類(lèi)型派生新類(lèi)型 --><xs:restriction base="book_Type"><xs:sequence><!-- 為name元素的類(lèi)型增加進(jìn)一步約束 --><xs:element name="name"><xs:simpleType><xs:restriction base="xs:token"><xs:maxLength value="20"/><xs:minLength value="4"/></xs:restriction></xs:simpleType></xs:element><!-- 不再定義price元素,即可認(rèn)為刪除了該元素 --></xs:sequence><!-- 刪除isbn屬性 --><xs:attribute name="isbn" use="prohibited"/></xs:restriction></xs:complexContent></xs:complexType> <!-- 定義restrict_book_Type類(lèi)型 --><xs:complexType name="restrict_book_Type"><xs:complexContent><!-- 通過(guò)限制book_Type類(lèi)型派生新類(lèi)型 --><xs:restriction base="book_Type"><xs:sequence><!-- 為name元素的類(lèi)型增加進(jìn)一步約束 --><xs:element name="name"><xs:simpleType><xs:restriction base="xs:token"><xs:maxLength value="20"/><xs:minLength value="4"/></xs:restriction></xs:simpleType></xs:element><!-- 不再定義price元素,即可認(rèn)為刪除了該元素 --></xs:sequence><!-- 為publish-date屬性的類(lèi)型增加進(jìn)一步約束 --><xs:attribute name="publish-date"><xs:simpleType><xs:restriction base="xs:date"><xs:maxExclusive value="2009-05-12"/><xs:minExclusive value="2007-05-12"/></xs:restriction></xs:simpleType> </xs:attribute><!-- 刪除isbn屬性 --><xs:attribute name="isbn" use="prohibited"/></xs:restriction></xs:complexContent></xs:complexType><xs:element name="book" type="restrict_book_Type"/> </xs:schema>擴(kuò)展混合內(nèi)容類(lèi)型
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"elementFormDefault="qualified" attributeFormDefault="unqualified"><!-- 定義一個(gè)book_Type類(lèi)型,該類(lèi)型下包含2個(gè)互斥子元素 --><xs:complexType name="book_Type" mixed="true"><!-- 使用choice定義2個(gè)子元素 --><xs:choice><xs:element name="name" type="xs:token"/><xs:element name="price" type="xs:decimal"/></xs:choice></xs:complexType><!-- 定義extend_book_Type類(lèi)型,必須保留mixed="true" --><xs:complexType name="extend_book_Type" mixed="true"><xs:complexContent><!-- 通過(guò)擴(kuò)展book_Type類(lèi)型派生新類(lèi)型 --><xs:extension base="book_Type"><xs:choice><!-- 新增定義2個(gè)子元素 --><xs:element name="type" type="xs:token"/><xs:element name="targetMarket" type="xs:token"/></xs:choice></xs:extension></xs:complexContent></xs:complexType> <xs:element name="book" type="extend_book_Type"/> </xs:schema>?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/nolonely/p/3496769.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的xml学习总结(三)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 软件测试学习(一)软件测试基础知识
- 下一篇: 全国翻译专业资格(水平)考试