Skip to main content
July 2, 2009
Answered

XMLSearch - Node Help

  • July 2, 2009
  • 1 reply
  • 1050 views

Hi Folks,

I've just recently started playing around with webservices and xml.  I have however come across an xml file (returned via cfhttp) that has a totally different structure to every other I've worked with so far.

I'm struggling to figure out the correct syntax to use in order to loop through the elements I need.

Here's an excerpt from the XML being returned;

<Report xsi:schemaLocation="LeadBreakdown http://83.142.224.108/ReportServer$sql2005?%2fRelational+Reports%2fLeadBreakdown&rs%3aFormat=XML&rc%3aSchema=True" Name="LeadBreakdown">

<Report>

<Report_Group1_Collection>

<Report_Group1>

<Detail_Collection>
<Detail Row="1" TransactionId="7049681" UID="btpo-y-d" ClickTime="2009-06-26T15:00:49" TransactionTime="2009-06-26T16:28:51" MID="34221" Merchant="Goldsmiths" Product="Goldsmiths" PID="5698" TransactionValue="180" Status="Validated" AC="25.20" Completed="2009-06-26T16:28:51"/>
</Detail_Collection>
</Report_Group1>

<Report_Group1>

<Detail_Collection>
<Detail Row="2" TransactionId="7054422" UID="btpo-y-d" ClickTime="2009-06-27T14:53:43" TransactionTime="2009-06-27T15:27:29" MID="34221" Merchant="Goldsmiths" Product="Goldsmiths" PID="5698" TransactionValue="111.25" Status="Validated" AC="15.58" Completed="2009-06-27T15:27:29"/>
<Detail Row="3" TransactionId="7054422" UID="btpo-y-d" ClickTime="2009-06-27T14:53:43" TransactionTime="2009-06-27T15:27:29" MID="34221" Merchant="Goldsmiths" Product="Goldsmiths" PID="5698" TransactionValue="111.25" Status="Validated" AC="15.58" Completed="2009-06-27T15:27:29"/>
<Detail Row="4" TransactionId="7054422" UID="btpo-y-d" ClickTime="2009-06-27T14:53:43" TransactionTime="2009-06-27T15:27:29" MID="34221" Merchant="Goldsmiths" Product="Goldsmiths" PID="5698" TransactionValue="111.25" Status="Validated" AC="15.58" Completed="2009-06-27T15:27:29"/>
<Detail Row="5" TransactionId="7054422" UID="btpo-y-d" ClickTime="2009-06-27T14:53:43" TransactionTime="2009-06-27T15:27:29" MID="34221" Merchant="Goldsmiths" Product="Goldsmiths" PID="5698" TransactionValue="111.25" Status="Validated" AC="15.58" Completed="2009-06-27T15:27:29"/>
</Detail_Collection>
</Report_Group1>

</Report_Group1_Collection>
</Report>
</Report>

And this is the code I'm currently using (the bold part is what I'm struggling with - everything else is there for reference so you can get a better idea of what I'm trying to do);

<!--- Include the XSD DateConvert Function to convert the raw date/time sent back in the XML --->
<cfinclude template="../functions/xsddateconvert.cfm">


<cfhttp url="wsurl" method="GET" resolveurl="NO" throwonerror="yes"><cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0"></cfhttp>

<cfscript>
  xmlContent = XmlParse(REReplace( cfhttp.FileContent, "^[^<]*", "", "all" ));
  xmlNode = xmlSearch(xmlContent, "//*[local-name()='Detail']");
</cfscript>

<!--- Table --->
<table cellpadding="5" width="100%">
<tr>
<td><b>Sale Date/Time</b></td>
<td><b><nobr>Programme Name</nobr></b></td>
<td><b>Commission</b></td>
<td><b>Clickref</b></td>
<td><b>EventID</b></td>
<td><b>Click Date/Time</b></td>
<td><b>Referrer</b></td>
</tr>


<tr>
<cfloop index="node" array="#xmlNode#">
  <cfset date = #Node.TransactionTime.xmlText#>
  <cfset programName = #Node.Merchant.xmlText#>
  <cfset commission = #Node.AC.xmlText#>
  <cfset clickref = #Node.UID.xmlText#>
  <cfset eventID = #Node.TransactionId.xmlText#>
  <cfset clickdate = #Node.ClickTime.xmlText#>
  <cfset referrer = 'Not Passed'>
 
  <cfoutput>
   <td>#LSDateFormat(date, "dd/mm/yy")# #LSTimeFormat(date, "HH:mm")#</td>
   <td>#programName#</td> 
   <td align="right">&pound;#Numberformat(commission, 0.00)#</td> 
   <td>#clickref#</td></tr>
   <td>#eventID#</td></tr>
   <td>#LSDateFormat(clickdate, "dd/mm/yy")# #LSTimeFormat(clickdate, "HH:mm")#</td></tr>
   <td>#referrer#</td></tr>
</cfoutput>
</cfloop>

</table>

I've been struggling with this since yesterday, so any help would be *very* appreciated

This topic has been closed for replies.
Correct answer mack_

I think the XmlSearch part should work properly, returning 5 rows but

you will have an error when outputting the results because you need to

access Node.XmlAttributes.TransactionTime instead of

Node.TransactionTime.

Mack

1 reply

July 3, 2009

Anyone?

mack_Correct answer
Participating Frequently
July 3, 2009

I think the XmlSearch part should work properly, returning 5 rows but

you will have an error when outputting the results because you need to

access Node.XmlAttributes.TransactionTime instead of

Node.TransactionTime.

Mack

July 3, 2009

Thanks Mack,

That was exactly what I needed!  I had to remove .xmltext from the end too, but it works perfectly now.

Your help is very much appreciated, it was driving me insane! :-D