Skip to main content
Inspiring
November 24, 2008
Question

XML HELP!

  • November 24, 2008
  • 2 replies
  • 312 views
First off, I am really light on using XML in CF. Having said that...I have to parse an XML document to use some of the information and loop it on a physician profile page. Using an example from a blog site, I am attempting (badly) to grab just the title, author, link, and category and put them into a temp recordset so I can display them on a page. Course it doesn't work.

Please help, client department is getting edgy and this is the last thing I have to do for them. THANKS!

Here is the script block:

<cfhttp url=" http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Search&db=pubmed&term=%28weadock%20WJ%5BAuthor%5D%29%20%20AND%20%20%28%22University%20of%20Michigan%22%5BAffiliation%5D%29" method="GET" />
<cfscript>
xmlfile = xmlparse(cfhttp.filecontent); //Parses the XML
/xmlsize = arraylen(xmlfile.item.xmlchildren); //item is the parent tree
xmlqry = QueryNew("title, link, author, category"); //Sets a query for output
QueryAddRow(xmlqry,xmlsize);

for(a=1;a LTE xmlsize;a=a+1) {
QuerySetCell(xmlqry,"title",xmlfile.item.Title.xmlText,a);
QuerySetCell(xmlqry,"link",xmlfile.item
.link.xmlText,a);
QuerySetCell(xmlqry,"author",xmlfile.item
.Author.xmlText,a);
QuerySetCell(xmlqry,"category",xmlfile.item
.category.xmlText,a);
}
</cfscript>

Here is the actual XML doc I am getting back:
This topic has been closed for replies.

2 replies

wkolczAuthor
Inspiring
November 24, 2008
Nope, using BlueDisaster (I mean Dragon). No cool RSS tags for me.
Inspiring
November 24, 2008
What version of CF are you using? Given this seems to be RSS, can you not
use <cffeed>?
http://livedocs.adobe.com/coldfusion/8/Tags_f_01.html

If not, read up on xmlSearch() and xpath.
http://livedocs.adobe.com/coldfusion/8/functions_t-z_24.html
http://www.zvon.org/xxl/XPathTutorial/General/examples.html

--
Adam