ColdFusion MX 6 & 7: XMLSearch() fails to return matching nodes when the XML document specifies a default namespace declaration
Issue
In ColdFusion MX 6 and ColdFusion MX 7, when you use XMLSearch() to run an XPath query using abbreviated syntax on an XML document that uses one or more default namespace declarations, the result may be that no nodes are matched. The problem isn't so much with XMLSearch() as it is with understanding how to use the XPATH expression language. This article describes how to write an XPATH expression that can deal with these special cases.
Reason
Consider how an XPath expression using abbreviated syntax is constructed to match child elements in a prefixed namespace. For a namespace declaration defined as xmlns:foo="myNameSpaceURI", element A belonging to the namespace foo is referenced through its Qualified Name (QName) foo:A to properly distinguish it from other A elements that might in other namespaces. Therefore, the XPath axis referring to the simple name A in the location path must use qualified name foo:A to match.
Solution
For a default namespace declaration, sometimes called a no-name namespace, such as , which lacks an explicit prefix, elements belonging to that default namespace can be referred by the QName that implies an empty string, such as :A, for example. Here, the XPath expression to match A elements in the default namespace should use the axis /:A.
When matching deep targets in an XML node, each axis in the full location path must use the corresponding QName such that to match all child elements C descended from B descended from root element A in the default namespace xmlns:"myNameSpaceURI", the XPath expression in abbreviated syntax should use the location path /:A/:B/:C .
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!
