浅谈XML Schema中的elementFormDefault属性
elementFormDefault属性与命名空间相关,其值可设置为qualified或unqualified
如果设置为qualified:
在XML文档中使用局部元素时,必须使用限定短名作为前缀
sean.xsd:
<?xmlversion="1.0"encoding="UTF-8"?> <xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sean="http://sean.com" targetNamespace="http://sean.com" elementFormDefault="qualified"> <xs:elementname="book_list"> <xs:complexType> <xs:sequence> <xs:elementname="book"type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
sean.xml:
<?xmlversion="1.0"encoding="UTF-8"?> <sean:book_listxmlns:sean="http://sean.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sean.comsean.xsd"> <sean:book>test</sean:book> </sean:book_list>
如果设置为unqualified:
在XML文档中使用局部元素时,可以省略限定短名
sean.xsd:
<?xmlversion="1.0"encoding="UTF-8"?> <xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sean="http://sean.com" targetNamespace="http://sean.com" elementFormDefault="unqualified"> <xs:elementname="book_list"> <xs:complexType> <xs:sequence> <xs:elementname="book"type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
sean.xml:
<?xmlversion="1.0"encoding="UTF-8"?> <sean:book_listxmlns:sean="http://sean.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sean.comsean.xsd"> <book>test</book> </sean:book_list>
虽然会间接很多,但是由于去掉了命名空间,所以不是很好理解
类似的属性还有attributeFormDefault,其规则与elementFormDefault是一样的
以上这篇浅谈XMLSchema中的elementFormDefault属性就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短