Namespaces are represented in the
xmlTree API as
structures, which contain prefix/URI pair for the namespace. Only one
xmlNs structure exists per namespace, and all nodes that use
that namespace point back to that namespace structure.
xmlTreeGetNsDef() gets the namespaces that are defined on
that node, which could be more than one.
xmlTreeGetNs() gets the
namespace that applies to that node, which can only be one.
Consider the following XML document:
<?xml version="1.0" encoding="UTF-8"?>
<myns:item>I'm an item!</myns:item>
There are two
xmlNs structure in this document, both of which
are defined on the
<top> element. Therefore,
<top> would return one
xmlNs, and the second could be retrieved by calling
xmlTreeGetNext() on the first. The
element defines them, but does NOT use either of them (it is in the
default, empty namespace), so calling
<top> will return nothing.
<item> nodes do not declare any namespaces themselves, so
xmlTreeGetNsDef() will return nothing for both of them. They
both use the
urn:exampleNs namespace, so calling
xmlTreeGetNs() will return the
xmlTree05_SetNS for examples
of working with namespaces in the