Whatever message this page gives is out now! Go check it out!
XmlSearch(xml, xpath, params)Parameter | Description | |
params | Optional. A struct that contains key-value pairs used by the XPath expression.When the xml argument is a string instead of an XML document object, the same struct is also consulted during the XML pre-parse step for parser options such as:
|
<cfscript>
params = structNew();
params["test"] = "food";
</cfscript>
<!--- find all nodes with element name as passed by variable test --->
<cfset result = xmlSearch(xmldoc,"/breakfast_menu/*[local-name() eq $test]", params)>xml | XML document object |
xpath | XPath expression |
XPath return type | ColdFusion representation |
Boolean | Boolean |
Null | "" (empty string) |
Number | Number |
String | String |
NodeSet | Array of XML nodes |
Result Tree Fragment | Array of XML nodes |
xml argument is an XML document object, XmlSearch() searches the parsed document object.If the xml argument is an XML string, ColdFusion performs a pre-parse step before evaluating the XPath expression. Starting in this release, that pre-parse rejects XML containing a <!DOCTYPE ...> declaration unless params.ALLOWDOCTYPEDECLARATION = true.Use this option only for trusted XML strings that are known to require a DOCTYPE declaration.<!--- Searching a string containing XML with a DOCTYPE declaration --->
<cfset params = {
ALLOWDOCTYPEDECLARATION = true,
ALLOWEXTERNALENTITIES = false,
ENTITYEXPANSIONLIMIT = 1000
}>
<cfset result = XmlSearch(myXmlString, "/root/item", params)><?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><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>