浅谈XML Schema中的elementFormDefault属性

2023-12-05 0 208

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

您可能感兴趣的文章:

  • Vue2ElementSchemaForm配置式生成表单的实现

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悠久资源 XML/RSS 浅谈XML Schema中的elementFormDefault属性 https://www.u-9.cn/biancheng/xmlrss/97152.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务