XML: do child nodes inherit parent's namespace prefix?

ε祈祈猫儿з 提交于 2019-12-18 12:48:36

问题


Assume the following XML document:

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

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


回答1:


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>

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



来源:https://stackoverflow.com/questions/25788871/xml-do-child-nodes-inherit-parents-namespace-prefix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!