How to define namespace prefixes to read node from xml node list using MapBasic

Products affected: MapInfo Pro ™, MapBasic ™
MIXmlSelectNodes will always return a non-null value if passed a valid node to search. The return value is a collection, but the collection will be empty if no matching nodes are found.

As for why no matching nodes are found, it’s because the XML file contains namespaces, and namespaces complicate XPath searches. To find nodes using XPath, the node names need to be prefixed with a something to identify the namespace even if the namespace is the default namespace (i.e., it has no prefix in the XML file). The namespace prefix to be used should be defined by the program using them.

The MapBasic XML library provides two ways to set the namespace prefixes. The programmer can set them using the MIXmlDocumentSetProperty function.

A simpler way to define the namespace prefixes is to let MapBasic do it by using SetNamespaces. For example:
    If Not SetNamespaces(ExampleNameXML) Then
        print "Failed to SetNamespaces.  Program canceled."
        exit sub
    End If

This sets a prefix for all of the namespaces defined in the root node. The prefixes all begin with “ns” followed by a number indicating the order the namespaces appear in the root node. Therefore, to get the node list of “ExampleName” nodes, use:
    ExampleList = MIXmlSelectNodes(xmlRootNode,"ns2:ExampleName")

Note that the prefix needs to be used on all XPath searches so that includes the calls to GetSingleNodeValue
UPDATED:  August 4, 2017