xmlNs xmlTreeLookupNsURI(xmlNode node, string URI)


  • node - the node you want to look up the namespace from

  • URI - the namespace URI you want to look up


  • the xmlNs for the URI namespace.

xmlTreeLookupNsURI() looks up a namespace based on the URI, if it exists. Handy if you want to assign a namespace to a node and you need to know if it's already declared in this scope so you don't create an unnecessary duplicate.

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">
        <item1 xmlns:bar="http://www.example.com">text</item1>

If you look up the http://www.example.com prefix from:

  • <item1>, we'll get bar

  • <item2>, we'll get foo

  • <item3>, we'll get nothing, because the namespace http://www.example.com is not defined for <item3>'s scope.


<$ns = (xmlTreeLookupNsURI($node, 'http://www.example.com'))>

xmlTreeGetNsURI, xmlTreeGetNsPrefix, xmlTreeLookupNsPrefix

Copyright © Thunderstone Software     Last updated: Oct 24 2023
Copyright © 2024 Thunderstone Software LLC. All rights reserved.