文章詳情頁
淺談XML Schema中的elementFormDefault屬性
瀏覽:142日期:2022-06-04 10:51:48
elementFormDefault屬性與命名空間相關,其值可設置為qualified或unqualified
如果設置為qualified:
在XML文檔中使用局部元素時,必須使用限定短名作為前綴
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>
如果設置為unqualified:
在XML文檔中使用局部元素時,可以省略限定短名
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>
雖然會間接很多,但是由于去掉了命名空間,所以不是很好理解
類似的屬性還有attributeFormDefault,其規(guī)則與elementFormDefault是一樣的
以上這篇淺談XML Schema中的elementFormDefault屬性就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持。
標簽:
XML/RSS
上一條:編寫xml沒有代碼提示的解決方法下一條:初識XML基礎知識
相關文章:
1. 不使用XMLHttpRequest對象實現(xiàn)Ajax效果的方法小結2. 用xslt將xml解析成xhtml的代碼3. asp下利用xml打包網(wǎng)站文件4. Android Studio實現(xiàn)格式化XML代碼順序5. python生成xml時規(guī)定dtd實例方法6. 一個用xslt樣式將xml解析為xhtml的類TransformBinder(兼容FF和IE7.0)7. 前端Website sitemap.xml文件搜索引擎優(yōu)化8. IDEA 插件 mapper和xml互相跳轉操作9. XML和YAML的使用方法10. 一個用于MySQL的PHP XML類
排行榜
