Handling XML Feeds with Children and Namespaces


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:

Here is a link to the XMLtool documentation in dotCMS:


#set($myXML = $""))

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


#set($itemlist= $myXML.find("/rss/channel/item"))

#foreach($items in $itemlist.iterator())

#set($item = $xmltool.parse($items))

##Use the escape html tool to see all the fields, debug, etc. as needed

<table border="1" style="width:100%;">

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


Have you created code you'd like to share with the dotCMS community?

Share your code Become a Contributor