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

XML Node Extraction

New Here ,
Mar 15, 2007 Mar 15, 2007

Copy link to clipboard

Copied

Okay

I have what I think is a simple question.

If i have a XML file that looks like the following

How would I extract the
<RecordSet Count="177" TotalCount="177">
count value and totalcount value from the XML file to store as a variable for later use?

I was trying to do the following but could not figure out the correct syntax

<cfset XMLSessionID = xmlparse(cfhttp.FileContent)>
<cfset FileName = #XMLSessionID.UpShotResponse.Select.xmltext#> (it's incomplete i know)

Just looking for a way to grab that attribute out of the xml value?

Thanks in advance

Rob
TOPICS
Advanced techniques

Views

312

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
LEGEND ,
Mar 15, 2007 Mar 15, 2007

Copy link to clipboard

Copied

you would use the xmlAttributes structure on the node you want the
information from.

I find <cfdump var="#XMLSessionID#"> to be most usefully when traversing
XML documents.

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
Advocate ,
Mar 15, 2007 Mar 15, 2007

Copy link to clipboard

Copied

I second Ian's suggestion. <cfdump>-ing XML docs has saved me more than once from pulling my hair out when dealing with XML in CF.

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
Community Expert ,
Mar 15, 2007 Mar 15, 2007

Copy link to clipboard

Copied

The are no end tags, so I would assume element RecordSet is within element Select and Select is within UpShotResponse. Then some possibilities are

XMLSessionID.XmlRoot["Select"]["RecordSet"].XmlAttributes["Count"]
XMLSessionID["UpShotResponse"]["Select"]["RecordSet"].XmlAttributes["Count"]


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
Advocate ,
Mar 16, 2007 Mar 16, 2007

Copy link to clipboard

Copied

LATEST
I should probably also mention, if you are worried about the format of your XML file changing, or will be dealing with repeating elements, you may also want to take a look at the CF XMLSearch() function. It allows you to use XPath to specify what XML elements you are looking for and typically returns the data as an array. The syntax is something like this:

XMLSearch(XMLSessionID, "//RecordSet")

XPath is a pretty powerful way to retreive data from XML, though if you are just looking for 1 element in an unchanging XML document, it might not be the most efficient thing to use.

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