• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help with xmlsearch

Explorer ,
Jun 18, 2007 Jun 18, 2007

Copy link to clipboard

Copied

I have been trying to get this final step completed for my application and just cannot seem to get a answer. I need to retriev a value from a xml post.

I am using xmlsearch to find the result:

<cfset customer.firstname = xmlsearch(xmlcustomer, "name[@part='first']")>
<cfset customer.lastname = xmlsearch(xmlcustomer, "name[@part='last']")>

I am getting returned:
<?xml version="1.0" encoding="UTF-8"?> <name part="first">MyFirstName</name>
<?xml version="1.0" encoding="UTF-8"?> <name part="last">MyLastName</name>

I obviously want just the first and last names but cannot seem to figure out how to get them out. Any help would be greatly appreciated.
TOPICS
Advanced techniques

Views

318

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jun 19, 2007 Jun 19, 2007
Thanks for the replies. I was able to work through it in the mean time and here is the way that I resolved it:

<cfset fName = xmlsearch(xmlcustomer, "name[@part='first']")>
<cfset xmlFName = xmlparse(fName[1][1], "yes")>
<cfset customer.firstname = xmlFName["name"]["XmlText"]>

<cfset lName = xmlsearch(xmlcustomer, "name[@part='last']")>
<cfset xmlLName = xmlparse(lName[1][1], "yes")>
<cfset customer.lastname = xmlLName["name"]["XmlText"]>

Votes

Translate

Translate
Advocate ,
Jun 19, 2007 Jun 19, 2007

Copy link to clipboard

Copied

xmlSearch() returns an XML node, which is a complex data type (think structure). Once you retrieve your XML node, you then have to parse out the data you want (do a <cfdump> on your xmlsearch() results to see what I mean).

The solution is pretty simple:
<cfset xmlNode= xmlsearch(xmlcustomer, "name[@part='first']")>
<cfset customer.firstname = xmlNode.xmlText>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 19, 2007 Jun 19, 2007

Copy link to clipboard

Copied

Hi spotsstang,

Here is a simple example, I want to search a employee with id of 23

<employee id="23">
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>

<cfset mydump = xmlSearch(myXml,'/employee [@id='23']/*') >
<cfdump var="#mydump #">

see the dump value, it will show you the returned structure.

hopefully this will help you in understanding of xmlsearch.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 19, 2007 Jun 19, 2007

Copy link to clipboard

Copied

LATEST
Thanks for the replies. I was able to work through it in the mean time and here is the way that I resolved it:

<cfset fName = xmlsearch(xmlcustomer, "name[@part='first']")>
<cfset xmlFName = xmlparse(fName[1][1], "yes")>
<cfset customer.firstname = xmlFName["name"]["XmlText"]>

<cfset lName = xmlsearch(xmlcustomer, "name[@part='last']")>
<cfset xmlLName = xmlparse(lName[1][1], "yes")>
<cfset customer.lastname = xmlLName["name"]["XmlText"]>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation