且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

XML:子节点是否继承父节点的命名空间前缀?

更新时间:2023-02-05 20:35:41

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