加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

elementFormDefault对XML /何时使用它是什么?

发布时间:2020-12-16 08:13:25 所属栏目:百科 来源:网络整理
导读:所以我发现了一些elementFormDefault值的定义: qualified – elements and attributes are in the targetNamespace of the schema unqualified – elements and attributes do not have a namespace 所以从那个定义,我会认为如果模式设置为限定,那么为什
所以我发现了一些elementFormDefault值的定义:

qualified – elements and attributes
are in the targetNamespace of the
schema

unqualified – elements and
attributes do not have a namespace

所以从那个定义,我会认为如果模式设置为限定,那么为什么必须在类型的命名空间前面?你甚至有一个场景,你会有一套不合格的事情?我试过谷歌,但我得到的是一对夫妇的W3C页面,是非常难以理解。

这是我现在正在使用的文件,当我声明targetNamespace与xmlns:target相同时,为什么需要将类型声明为“target:TypeAssignments”?

<?xml version="1.0" encoding="UTF-8"?>
<schema 
    xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:target="http://www.levijackson.net/web340/ns"
    targetNamespace="http://www.levijackson.net/web340/ns" elementFormDefault="qualified"
    >

<element name="assignments">
    <complexType>
        <sequence>
            <element name="assignments" type="target:TypeAssignments" minOccurs="1" maxOccurs="unbounded"></element>
        </sequence>
    </complexType>
</element>

<complexType name="TypeAssignments">
    <sequence>
        <element name="assignment" type="target:assignmentInfo" minOccurs="0" maxOccurs="unbounded"></element>
    </sequence>
</complexType>

<complexType name="assignmentInfo">
    <sequence>
            <element name="name" type="string"></element>
            <element name="page" type="target:TypePage"></element>
            <element name="file" type="target:TypeFile" minOccurs="0" maxOccurs="unbounded"></element>
    </sequence>
    <attribute name="id" type="string" use="required"/>
</complexType>

<simpleType name="TypePage">
    <restriction base="integer">
        <minInclusive value="50" />
        <maxInclusive value="498" />
    </restriction>
</simpleType>

<simpleType name="TypeFile">
    <restriction base="string">
        <enumeration value=".xml" />
        <enumeration value=".dtd" />
        <enumeration value=".xsd" />
    </restriction>
</simpleType>

</schema>

提前致谢,
Levi

ElementFormDefault与模式中的类型的命名空间无关,它是关于符合模式的XML文档中的元素的命名空间。

这里是规范的相关部分:

06000

这意味着,您在模式顶部声明的targetNamespace只适用于符合模式的XML文档中的元素,如果elementFormDefault是“qualified”或元素在模式中显式声明为form =“qualified” 。

例如:如果elementFormDefault是不合格的 –

<element name="name" type="string" form="qualified"></element>
<element name="page" type="target:TypePage"></element>

将把期望的“name”元素放在targetNamespace中,将“page”元素放在null命名空间中。

为了节省你不得不对每个元素声明放置form =“qualified”,声明elementFormDefault =“qualified”意味着targetNamespace适用于每个元素,除非通过在元素声明上放置form =“unqualified”来覆盖。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读