Get XML values according to given xPath query

xmlSearch(xmlNode, xpath [, params]) → returns array

Argument Reference

xmlNode xml

An XML document object

xpath string

xPath expression

params struct

CF 10+ A struct with key value pairs to be used a variables within the xPath Expression

Links more information about xmlSearch

Sample code invoking the xmlSearch function

XPath extracts 'name' property from every user given in the XML collection

<cfsavecontent variable="xmlstring">
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
        <user id="1">
        <user id="2">
                <street>Long Road</street>
    xml = XMLParse(xmlstring);
    result = xmlSearch(xml,'users//name');
    userlist = '';
    for(i = 1; i <= ArrayLen(result); i++) {
        userlist = ListAppend(userlist,result[i].XmlText);

Expected Result: Me,You

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub