xmlTreeSetNs

SYNOPSIS

xmlNode xmlTreeSetNs(xmlNode node, xmlNs ns)

Parameters:

  • node - the xmlNode to set the namespace for

  • ns - the namespace to use for node

Returns:

  • the node


DESCRIPTION
xmlTreeSetNs() assigns the namespace ns to be used with node. Note that this is different from xmlTreeNewNs(), which simply declares the namespace to exist, but does not place any nodes in that namespace.


EXAMPLE
Given the simple one-element document <top/>, calling

<$ns = (xmlTreeNewNs($top, 'ts', 'urn:Thunderstone'))>

Would result in the following document: <top xmlns:ts="urn:Thunderstone"/>

The urn:Thunderstone namespace exists, but isn't being used by <top/>. Additionally calling

<$ret = (xmlTreeSetNs($top, $ns))>

would result in the following document: <ts:top xmlns:ts="urn:Thunderstone"/>

Here the namespace has been declared, and the node is set to it.


CAVEATS
You may have noticed that if using the empty prefix, the xmlTreeSetNs() isn't necessary for correct output. Making a new ns with no prefix but not setting with xmlTreeSetNs() would produce:

<top xmlns="urn:Thunderstone"/>

While this will result in correct output, it's still recommended to call xmlTreeSetNs() to assign the namespace to any node that needs it. If the prefix for the urn:Thunderstone ever changed, the prefix on <top> would only be properly set if it was assigned to the namespace with xmlTreeSetNs().


SEE ALSO
xmlTreeGetNs, xmlTreeNewNs


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.