user3071284
user3071284

Reputation: 7100

XmlSearch() does not process an individual XML node in an array

I have an XML document that I've assigned to a ColdFusion variable. Calling XmlSearch() on this document produces an array of XML nodes. Calling XmlSearch() on one of those XML nodes produces the same output as if calling it on the original XML document.

What could the issue be?

Here's a code example (CFScript):

// xmlSource is an XML file that has been read in
xmlDoc = XmlParse(xmlSource);

// "return" is a high-level XML node in xmlSource that appears more than one time
xmlNodeArray = XmlSearch(xmlDoc, "//return");

// a single "return" node from xmlDoc
xmlNode = xmlNodeArray[1];

// "recipients" is an XML node that appears one or more times beneath each "return" XML node
xmlArray = XmlSearch(xmlNode, "//recipients");

// this prints out all of the "recipients" nodes in xmlDoc instead of just from xmlNode
WriteDump(xmlArray); 

Upvotes: 1

Views: 231

Answers (1)

user3071284
user3071284

Reputation: 7100

The issue was with the XPath. Changing

xmlArray = XmlSearch(xmlNode, "//recipients");

to

xmlArray = XmlSearch(xmlNode, "./recipients");

fixed it.

Upvotes: 1

Related Questions