我是靠谱客的博主 呆萌西装,这篇文章主要介绍简单介绍XML Schema中的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中的elementFormDefault属性的全部内容,更多相关简单介绍XML内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(91)

评论列表共有 0 条评论

立即
投稿
返回
顶部