XmlSearch()不处理数组中的单个XML节点

时间:2016-01-28 15:57:40

标签: xml xpath coldfusion

我有一个XML文档,我已将其分配给ColdFusion变量。在此文档上调用XmlSearch()会生成一个XML节点数组。在其中一个XML节点上调用XmlSearch()会产生与在原始XML文档上调用它相同的输出。

问题是什么?

这是一个代码示例(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); 

1 个答案:

答案 0 :(得分:1)

问题在于XPath。改变

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

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

修好了。