文章詳情頁(yè)
淺談XML Schema中的elementFormDefault屬性
瀏覽:84日期:2022-06-04 10:51:48
elementFormDefault屬性與命名空間相關(guān),其值可設(shè)置為qualified或unqualified
如果設(shè)置為qualified:
在XML文檔中使用局部元素時(shí),必須使用限定短名作為前綴
sean.xsd:
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sean="http://sean.com" targetNamespace="http://sean.com" elementFormDefault="qualified"> <xs:element name="book_list"> <xs:complexType> <xs:sequence> <xs:element name="book" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
sean.xml:
<?xml version="1.0" encoding="UTF-8"?> <sean:book_list xmlns:sean="http://sean.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sean.com sean.xsd"> <sean:book>test</sean:book> </sean:book_list>
如果設(shè)置為unqualified:
在XML文檔中使用局部元素時(shí),可以省略限定短名
sean.xsd:
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sean="http://sean.com" targetNamespace="http://sean.com" elementFormDefault="unqualified"> <xs:element name="book_list"> <xs:complexType> <xs:sequence> <xs:element name="book" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
sean.xml:
<?xml version="1.0" encoding="UTF-8"?> <sean:book_list xmlns:sean="http://sean.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sean.com sean.xsd"> <book>test</book> </sean:book_list>
雖然會(huì)間接很多,但是由于去掉了命名空間,所以不是很好理解
類似的屬性還有attributeFormDefault,其規(guī)則與elementFormDefault是一樣的
以上這篇淺談XML Schema中的elementFormDefault屬性就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持。
標(biāo)簽:
XML/RSS
相關(guān)文章:
1. javascript xml xsl取值及數(shù)據(jù)修改第1/2頁(yè)2. 存儲(chǔ)于xml中需要的HTML轉(zhuǎn)義代碼3. XML入門的常見問題(一)4. android studio xml文件實(shí)現(xiàn)添加注釋5. 為Android系統(tǒng)添加config.xml 新配置的設(shè)置6. 輕松學(xué)習(xí)XML教程7. XML相關(guān)技術(shù)資料8. python解析xml文件方式(解析、更新、寫入)9. python對(duì)XML文件的操作實(shí)現(xiàn)代碼10. HTML中的XML數(shù)據(jù)島記錄編輯與添加
排行榜
