xmlNs xmlTreeLookupNsPrefix(xmlNode node, string prefix)


  • node - the xmlNode to lookup the namespace from

  • prefix - the prefix of the namespace to lookup


  • the namespace that uses prefix

xmlTreeLookupNsPrefix() looks up the namespace in the scope of node that uses the prefix prefix. Useful if you know that a namespace exists in the tree but you don't have the xmlNs of it.

This does not search the entire XML tree, but only the namespace scope of the given node, which is the current node and all nodes above it. If a namespace isn't available for a node to use, then it won't be found from a search on that node.

For example, given the following document:

  <container xmlns:foo="http://www.example.com/container">
    <item1 xmlns:foo="http://www.example.com/item">text</item1>

If you look up the foo prefix from:

  • <item1>, we'll get http://www.example.com/item

  • <item2>, we'll get http://www.example.com/container

  • <item3>, we'll get nothing, because the prefix foo is not defined for <item3>'s scope.


<$ns = (xmlTreeLookupNsPrefix($node, 'ts'))>

xmlTreeGetNsURI, xmlTreeGetNsPrefix, xmlTreeLookupNsURI

Copyright © Thunderstone Software     Last updated: Jul 17 2021
Copyright © 2021 Thunderstone Software LLC. All rights reserved.