Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 651
Dmitry Volosnykh Avatar asked Sep 11 '14 13:09

Dmitry Volosnykh


People also ask

What is an XML namespace prefix used for?

An XML namespace is a collection of names that can be used as element or attribute names in an XML document. The namespace qualifies element names uniquely on the Web in order to avoid conflicts between elements with the same name.

How to declare namespace in XQuery?

Declaring a Default Element Namespace in XQuerydeclare default element namespace "http://www.w3.org/1999/xhtml"; An XQuery program that has this prolog declaration will use the XHTML namespace for all elements where a namespace is not explicitly defined (for example, with a namespace prefix).

What is namespace in marklogic?

Namespaces can be defined for a group to apply to all HTTP, ODBC, XDBC, and WebDAV servers in a group or for a particular HTTP, ODBC, XDBC, or WebDAV server. However, a namespace cannot be defined to apply to a particular forest, database, or XQuery program.

What is namespace in @xmlelement?

XML namespaces provide a method for qualifying the names of XML elements and XML attributes in XML documents. A qualified name consists of a prefix and a local name, separated by a colon. The prefix functions only as a placeholder; it is mapped to a URI that specifies a namespace.


1 Answers

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.

like image 88
har07 Avatar answered Oct 29 '22 04:10

har07