Dmitrii Volosnykh
Dmitrii Volosnykh

Reputation: 1185

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

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/>?

Upvotes: 40

Views: 13323

Answers (1)

har07
har07

Reputation: 89285

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.

Upvotes: 54

Related Questions