浅谈XML Schema中的elementFormDefault属性
导读:收集整理的这篇文章主要介绍了浅谈XML Schema中的elementFormDefault属性,觉得挺不错的,现在分享给大家,也给大家做个参考。 elementFormDefault属...
收集整理的这篇文章主要介绍了浅谈XML Schema中的elementFormDefault属性,觉得挺不错的,现在分享给大家,也给大家做个参考。 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,其规则与elementFormDefault是一样的
以上这篇浅谈XML Schema中的elementFormDefault属性就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
您可能感兴趣的文章:- 一个简单的XML Schema的例子
- Spring中XML schema扩展机制的深入讲解
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 浅谈XML Schema中的elementFormDefault属性
本文地址: https://pptw.com/jishu/608203.html
