For the complete experience, please enable JavaScript in your browser. Thank you!

  • Creative Cloud
  • Photoshop
  • Illustrator
  • InDesign
  • Premiere Pro
  • After Effects
  • Lightroom
  • See all
  • See plans for: businesses photographers students
  • Document Cloud
  • Acrobat DC
  • eSign
  • Stock
  • Elements
  • Marketing Cloud
  • Analytics
  • Audience Manager
  • Campaign
  • Experience Manager
  • Media Optimizer
  • Target
  • See all
  • Acrobat Reader DC
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player
  • All products
  • Creative Cloud
  • Individuals
  • Photographers
  • Students and Teachers
  • Business
  • Schools and Universities
  • Marketing Cloud
  • Document Cloud
  • Stock
  • Elements
  • All products
  • Get Support
    Find answers quickly. Contact us if you need to.
    Start now >
  • Learn the apps
    Get started or learn new ways to work.
    Learn now >
  • Ask the community
    Post questions and get answers from experts.
    Start now >
    • About Us
    • Careers At Adobe
    • Investor Relations
    • Privacy  |  Security
    • Corporate Responsibility
    • Customer Showcase
    • Events
    • Contact Us
News
    • 3/22/2016
      Adobe Summit 2016: Are You An Experience Business?
    • 3/22/2016
      Adobe Announces Cross-Device Co-op to Enable People-Based Marketing
    • 3/22/2016
      Adobe and comScore Advance Digital TV and Ad Measurement
    • 3/22/2016
      Adobe Marketing Cloud Redefines TV Experience
CFML Reference / 

XmlSearch

Adobe Community Help


Applies to

  • ColdFusion

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

Description

Uses an XPath language expression to search an XML document object.

Returns

The results of the XPath search. For details, see Usage.

Category

XML functions

Function syntax

XmlSearch(xmlDoc, xPathString, params)

See also

cfxml, IsXML, XmlChildPos, XmlParse, XmlTransform; Using XML and WDDX in the Developing ColdFusion Applications

History

ColdFusion 10: Added support for XPath 2.0 syntax and for passing variables to XPath expressions.

ColdFusion 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.

Parameters

Parameter

Description

params

Optional. A struct that contains key-value pair (variable name and value) document object as shown in the following example:

<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)>

 

xmlDoc

XML document object

xPathString

XPath expression

Usage

The 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.

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

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.

Example

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>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Choose your region United States (Change)   Products   Downloads   Learn & Support   Company
Choose your region Close

Americas

Europe, Middle East and Africa

Asia Pacific

  • Brasil
  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Cyprus - English
  • Česká republika
  • Danmark
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Greece - English
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Malta - English
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • Southeast Asia (Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam) - English
  • 台灣

Commonwealth of Independent States

  • Includes Armenia, Azerbaijan, Belarus, Georgia, Moldova, Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Ukraine, Uzbekistan

Copyright © 2016 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

AdChoices