More Fun with XML and executeXPath

More Fun with XML and executeXPath

Related post https://help.zoho.com/portal/en/community/topic/help-with-xml

Here's the next xml do-dad I need to tackle (yes, it's for my Amazon SES+ZOHO app)

  1. <GetSendStatisticsResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
  2.   <GetSendStatisticsResult>
  3.     <SendDataPoints>
  4.       <member>
  5.         <DeliveryAttempts>2</DeliveryAttempts>
  6.         <Timestamp>2011-04-17T12:25:00Z</Timestamp>
  7.         <Rejects>0</Rejects>
  8.         <Bounces>0</Bounces>
  9.         <Complaints>0</Complaints>
  10.       </member>
  11.       <member>
  12.         <DeliveryAttempts>16</DeliveryAttempts>
  13.         <Timestamp>2011-04-17T09:55:00Z</Timestamp>
  14.         <Rejects>0</Rejects>
  15.         <Bounces>0</Bounces>
  16.         <Complaints>0</Complaints>
  17.       </member>
  18.     </SendDataPoints>
  19.   </GetSendStatisticsResult>
  20.   <ResponseMetadata>
  21.     <RequestId>33aeb2b9-68f8-11e0-b615-9ba76660ea6c</RequestId>
  22.   </ResponseMetadata>
  23. </GetSendStatisticsResponse>
I can do this brute-force method:

  1. MAP={ "KEY" : "LIST" };
  2. XMAP = postUrl("http://some url to a php file",MAP);
  3. MYLIST1=(XMAP.toXML().executeXPath("//:DeliveryAttempts/text()").toXmlList()).toString().toList();
  4. MYLIST2=(XMAP.toXML().executeXPath("//:Timestamp/text()").toXmlList()).toString().toList();
  5. MYLIST3=(XMAP.toXML().executeXPath("//:Rejects/text()").toXmlList()).toString().toList();
  6. MYLIST4=(XMAP.toXML().executeXPath("//:Bounces/text()").toXmlList()).toString().toList();
  7. MYLIST5=(XMAP.toXML().executeXPath("//:Complaints/text()").toXmlList()).toString().toList();
But what I'd really like to do is get this in a form that enables generating a table in an html view, like

  1. HTML_TABLE = "<table width='400' border='1' cellpadding='1' cellspacing='1'><tbody><tr><td>DeliveryAttempts</td><td>Timestamp</td><td>Rejects</td><td>Bounces</td><td>Complaints</td></tr>";
  2. for each element in XMAP
  3. {
  4. HTML_TABLE = HTML_TABLE + "<tr><td>"+element.DeliveryAttempts+"</td><td>"+element.Timestamp+"</td><td>"+element.Rejects+"</td><td>"+element.Bounces+"</td><td>"+element.Complaints+"</td></tr>";
  5. }
  6. HTML_TABLE = HTML_TABLE + "</tbody></table>";

Even better would be to order by the time-stamp!

John M. Whitney