当前位置: 代码网 > it编程>网页制作>Xml > 浅谈XML Schema中的elementFormDefault属性

浅谈XML Schema中的elementFormDefault属性

2024年05月15日 Xml 我要评论
elementformdefault属性与命名空间相关,其值可设置为qualified或unqualified如果设置为qualified:在xml文档中使用局部元素时,必须使用限定短名作为前缀sea

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属性就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com