elementFormDefault属性详细介绍
来源:爱站网时间:2022-12-07编辑:网友分享
今天我们就来学习下elementFormDefault属性的相关资料吧,如果你需要了解清楚,那就看看下面这篇文章,爱站技术频道小编在这里做了详细的分析,有兴趣了解一下也无妨。
elementFormDefault属性与命名空间相关,其值可设置为qualified或unqualified
如果设置为qualified:
在XML文档中使用局部元素时,必须使用限定短名作为前缀
sean.xsd:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?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:
|
1
2
3
4
5
6
|
<?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:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?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:
|
1
2
3
4
5
6
|
<?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是一样的
希望爱站技术频道小编收集到的elementFormDefault属性内容能让你收获不一样的知识, 本平台提供给大家参考的技术文章都很不错,如果你需要,随时来关注收藏都可以。