ColdFusion 9.0 Resources |
XmlSearchSee alsocfxml, IsXML, XmlChildPos, XmlParse, XmlTransform; Using XML and WDDX in the Developing ColdFusion Applications HistoryColdFusion 8: Added support for returning any valid XPath result, not just arrays of XML object nodes. ColdFusion MX 7: Added support for attribute searches. ColdFusion MX: Added this function. UsageThe XmlSearch function attempts to return the values returned by the search whenever possible. For example, if the XPath expression returns a Boolean, the CFML variable is assigned a true or false value. The following table lists XPath expression result data types and how they are represented in the CFML return value.
Results that are Unknown or have an unresolved variable in the expression throw an error. XPath is specified by the World Wide Web Consortium (W3C). For detailed information on XPath, including XPath expression syntax, see the W3C website at www.w3.org/TR/xpath. ExampleThe following example extracts the elements named last, which contain employee last names, from an XML file, and displays the names. The employeesimple.xml file contains the following XML: <?xml version="1.0" encoding="UTF-8"?> <employee> <!-- A list of employees --> <name EmpType="Regular"> <first>Almanzo</first> <last>Wilder</last> </name> <name EmpType="Contract"> <first>Laura</first> <last>Ingalls</last> </name> </employee> The CFML file contains the following lines: <cfscript> myxmldoc = XmlParse("C:\CFusionMX7\wwwroot\examples\employeesimple.xml"); selectedElements = XmlSearch(myxmldoc, "/employee/name/last"); for (i = 1; i LTE ArrayLen(selectedElements); i = i + 1) writeoutput(selectedElements[i].XmlText & "<br>"); </cfscript> |