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

XML默认命名空间问题

发布时间:2020-12-16 23:21:06 所属栏目:百科 来源:网络整理
导读:假设我有以下 XML模式文件和以下 XML文档文件.我有两个问题, 由于XML Schema文件中没有指定目标名称空间,因此Information元素中的命名空间是什么? 在XML文档文件中,使用“信息”时,它属于哪个命名空间?请注意,在这种情况下,我没有从XML文档文件中引用XML S
假设我有以下 XML模式文件和以下 XML文档文件.我有两个问题,

>由于XML Schema文件中没有指定目标名称空间,因此Information元素中的命名空间是什么?
>在XML文档文件中,使用“信息”时,它属于哪个命名空间?请注意,在这种情况下,我没有从XML文档文件中引用XML Schema文件.

XML Schema文件:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="Information" type="xs:string"/>
</xs:schema>

XML文档文件:

<?xml version="1.0" encoding="utf-8"?>
<Information>Hello XML</Information>

提前致谢,
乔治

解决方法

Information元素将不在命名空间中.要将它放在默认命名空间中,您必须在标记中指定该命名空间.

<Information xmlns="http://www.mydefaultnamespace.com">

从Oracle article:

No Namespace

No namespace exists when there is no default namespace in scope. A {default namespace} is one that is declared explicitly using xmlns. When a {default namespace} has not been >declared at all using xmlns,it is incorrect to say that the elements are in {default >namespace}. In such cases,we say that the elements are in {no namespace}. {no namespace} >also applies when an already declared {default namespace} is undeclared.

这是一个非常全面的命名空间资源:

XML Namespaces FAQ

(编辑:李大同)

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

    推荐文章
      热点阅读