Skip to main content
lovewebdev
Inspiring
October 31, 2010
Question

Retrieve XML

  • October 31, 2010
  • 1 reply
  • 1770 views

I have XML that looks like this

<?xml version="1.0" encoding="utf-8"?>
<rsp>
 
<videos total="39" >
  <video id="565455" title="With Love" />
 
</videos>
</rsp>

I'm trying to dispay the xml using coldfusion. I've done this before but the problem i have this time is trying to access the id and title values in the video.

Can someone give me a simple example of retrieving this?

I have:

<cfset mydoc = XmlParse(CFHTTP.FileContent)>
<cfset pb = mydoc.rsp.XmlChildren>
<cfset size = ArrayLen(pb)>

<cfset myquery = QueryNew("id, title")>
<cfset temp = QueryAddRow(myquery, #size#)>

<cfloop index="i" from = "1" to = #size#>

??

</cfloop>

Sorry if my cf is so bad!!

This topic has been closed for replies.

1 reply

Inspiring
October 31, 2010

Have a look @ XPath & xmlSearch().

A good beginners' tutorial on XPath:

http://www.zvon.org/comp/r/tut-XPath_1.html

xmlSearch() docs:

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-78e8.html

Have you also read the XML section of the CF docs?

http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7fb3.html

It pretty-much covers everything (... OK... most things...) you need to know about accessing/addressing XML data with CF.


Probably in this case - if your XML really is that straight fwd, I'd just access the values directly with dot-notation, as per the CF docs above, in which it's all explained.

--

Adam

lovewebdev
Inspiring
October 31, 2010

Hi Adam, Thanks so much.

I couldnt find how to access a value inside the tag.

Could you send me to a direct example. I think the info is little over my head.

Inspiring
October 31, 2010

Did the stuff here - http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec133ba-7fe6.html#WSc3ff6d0ea77859461172e0811cbec22c24-78e9 - not make sense?

What did you try?  Where's some code that you tried?

I'm not one to just give people "direct" answers here, sorry: I don't believe that this helps much.

However I'm happy to help you work through it, if you give it a go yourself.

--

Adam