Handling XML Feeds with Children and Namespaces

Description

The code below is a quick example on how to handle nested children in a simple XML feed and how to handle namespace fields that have a ":" in them.

Here is a link to xpath sytnax for those not familiar: http://www.w3schools.com/xpath/xpath_syntax.asp

Here is a link to the XMLtool documentation in dotCMS: http://dotcms.com/docs/latest/XMLTool

Code

${esc.h}set(${esc.d}myXML = ${esc.d}xmltool.read("http://fruitfromthevine.wordpress.com/feed/"))

<h2>Fruit From the Vine XML Feed</h2>
<table  border="1" style="width:100%;">
  <tr>
    <th><h2>Title</h2></th>
    <th><h2>Link</h2></th>
    <th><h2>Description</h2></th>
    <th><h2>Update Period</h2></th>
    <th><h2>Update Frequency</h2></th>
  </tr>

     <tr>
      <td>
         ${esc.d}myXML.find("/rss/channel/title").text</td>
      <td>
         ${esc.d}myXML.find("/rss/channel/link").text</td>
      <td>
         ${esc.d}myXML.find("/rss/channel/description").text</td>
      <td>
         ${esc.d}myXML.find("/rss/channel/sy:updatePeriod").text</td>
      <td>
          ${esc.d}myXML.find("/rss/channel/sy:updateFrequency").text</td>
     </tr>
</table>

<h2>Articles</h2>  
${esc.h}set(${esc.d}itemlist= ${esc.d}myXML.find("/rss/channel/item"))

${esc.h}foreach(${esc.d}items in ${esc.d}itemlist.iterator())

${esc.h}set(${esc.d}item = ${esc.d}xmltool.parse(${esc.d}items))

${esc.h}${esc.h}Use the escape html tool to see all the fields, debug, etc. as needed
${esc.h}${esc.h}${esc.d}esc.html(${esc.d}item)

<table border="1" style="width:100%;">
  <tr>
    <th><h3>Title</h3></th>
    <th><h3>Link</h3></th>
  </tr>

<a href="/test/test-maps.html"> </a>
     <tr>
      <td style="width:30%;">${esc.d}item.find("/item/title").text</td>
      <td><a href="${esc.d}{item.find("/item/link").text}" target="blank">${esc.d}item.find("/item/link").text</a></td>
     </tr>
</table>

${esc.h}end