XML:子节点是否继承父节点的命名空间前缀? [英] XML: do child nodes inherit parent's namespace prefix?

查看:31
本文介绍了XML:子节点是否继承父节点的命名空间前缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有以下 XML 文档:

Assume the following XML document:

<root xmlns:foo="...">
  <foo:parent>
    <child/>
  </foo:parent>
</root>

child 元素是否属于对应于前缀 foo 的命名空间?就像 ?

does child element belong to a namespace that corresponds to the prefix foo? Just like in case <foo:child/>?

推荐答案

没有.默认情况下,子节点继承前缀命名空间,并且需要显式添加前缀,正如您提到的:<foo:child/>.

No. Child nodes do not inherit prefixed namespace by default, and explicit prefix addition needed as you mentioned : <foo:child/>.

但是它们确实继承祖先的默认命名空间(没有前缀的命名空间),如果有的话:

But they do inherit ancestor's default namespace (the one without prefix), if any :

<root xmlns:foo="...">
  <parent xmlns="bar">
    <child/>
  </parent>
</root>

节点位于相同的命名空间中,URI 为 bar.

<parent> and <child> nodes are in the same namespace which URI is bar.

这篇关于XML:子节点是否继承父节点的命名空间前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆