Uses an XPath language expression to search an XML document object.
An array of XML object nodes that match the search criteria.
XmlSearch(xmlDoc, xPathString)
cfxml, IsXML, XmlChildPos, XmlParse, XmlTransform; Using XML and WDDX in ColdFusion MX Developer's Guide
ColdFusion MX 7: Added support for attribute searches.
ColdFusion MX: Added this function.
| Parameter | Description |
|---|---|
|
xmlDoc |
XML document object |
|
xPathString |
XPath expression |
The XmlSearch function does not support complete XPath syntax. It only supports XPath expressions that return one or more XML nodes and attribute searches. XPath expressions that return any other type of value, such as a string, number, or Boolean, generate errors.
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.
The 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>
ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting
Version 7
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00000672.htm
Comments
davidfekke said on Nov 18, 2005 at 1:46 PM : serat said on Nov 19, 2005 at 12:15 PM : Return-Path said on Apr 11, 2006 at 2:40 AM :