文章詳情頁(yè)
淺談XML Schema中的elementFormDefault屬性
瀏覽:112日期: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. .NET 中配置從xml轉(zhuǎn)向json方法示例詳解2. xml中的空格之完全解說3. 使用Spry輕松將XML數(shù)據(jù)顯示到HTML頁(yè)的方法4. XML 非法字符(轉(zhuǎn)義字符)5. Java dom4j創(chuàng)建解析xml文檔過程解析6. 基于android studio的layout的xml文件的創(chuàng)建方式7. 關(guān)于html嵌入xml數(shù)據(jù)島如何穿過樹形結(jié)構(gòu)關(guān)系的問題8. python xml模塊的簡(jiǎn)單使用9. XML 取得元素的字符數(shù)據(jù)10. Android Studio實(shí)現(xiàn)格式化XML代碼順序
排行榜
