浅谈XML Schema中的elementFormDefault属性

栏目: 编程语言 · XML · 发布时间: 7年前

内容简介:下面小编就为大家带来一篇浅谈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属性》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

C++沉思录

C++沉思录

Andrew Koenig、Barbara Moo / 黄晓春、孟岩(审校) / 人民邮电出版社 / 2002-11-01 / 50.00元

《C++ 沉思录》集中反映了C++的关键思想和编程技术,不仅告诉你如何编程,还告诉你为什么要这样编程。本书曾出现在众多的C++专家推荐书目中。 这将是C++程序员的必读之作。因为: 它包含了丰富的C++思想和技术,从详细的代码实例总结出程序设计的原则和方法。 不仅教你如何遵循规则,还教你如何思考C++编程。 既包括面向对象编程也包括泛型编程。 探究STL这一近年来C++最重要的新成果的内在思想。一起来看看 《C++沉思录》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码