我有一个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);
答案 0 :(得分:1)
问题在于XPath。改变
xmlArray = XmlSearch(xmlNode, "//recipients");
到
xmlArray = XmlSearch(xmlNode, "./recipients");
修好了。