I needed a way to filter out nodes from an XML document
in CFMX. XPath is a great mechanism for finding nodes,
so I decided to throw together a little UDF which would
allow me to delete any nodes in an XPath expression. Here's
the UDF:
/****************************************************************
UDF: xmlDelete(xml, xpath)
Author: Dan G. Switzer, II
Date: 5/27/2004
Arguments:
xml - the xml document to delete nodes from
xpath - the xpath statement which defines the nodes to delete
****************************************************************/
function xmlDelete(oXml, sXpath){
var oNodes = xmlSearch(oXml, sXpath);
var bNodesFound = iif(arrayLen(oNodes) gt 0, true, false);
while( arrayLen(oNodes) GT 0 ){
arrayClear(oNodes[1]);
arrayDeleteAt(oNodes, 1);
}
return bNodesFound;
}
If you need to delete all the nodes which have an attribute of
"active" where the value is "false", you can use the follow:
xmlDelete(xmlObject, "//*[@active="false"]");
The xmlObject will now have all of the inactive nodes removed
from it.
2 Comments
Comments for this entry have been disabled.