XMLTool documentation for the dotCMS Content Management System

The XMLTool can be used to parse an remote xml file and iterate over each object returned in the xml file as needed

Class: com.dotmarketing.viewtools.xmltool.java

Name: ${esc.d}xmltool - (way to refer to the tool in the Velocity context)

Toolbox Configuration Example

  <tool>
    <key>xmltool</key>
    <scope>application</scope>
    <class>com.dotmarketing.viewtools.xmltool</class>
  </tool>

Here's a usage example created by Chris Falzone of the dotCMS community - Thanks Chris!

Example of a xml page that can be parsed: http://www.w3schools.com/XML/cd_catalog.xml

To parse the XML file on a dotCMS page, preview the following example which is doing a parse of an xml page and then iterating over 5 objects in the parse at the bottom of this document:

#set($myXML = $xmltool.read("https://www.w3schools.com/XML/cd_catalog.xml"))
<table  border="1" style="width:100%;">
  <tr>
    <th><h2>Title</h2></th>
    <th><h2>Artist</h2></th>
    <th><h2>Country</h2></th>
    <th><h2>Company</h2></th>
    <th><h2>Price</h2></th>
    <th><h2>Year</h2></th>
  </tr>
#foreach($cd in $myXML.children().iterator())
  #set($cdXML = $xmltool.parse($cd))
    #if($velocityCount<=5)
     <tr>
      <td>
     $cdXML.TITLE.text </td>
      <td>
      $cdXML.ARTIST.text </td>
      <td>
      $cdXML.COUNTRY.text </td>
      <td>
      $cdXML.COMPANY.text </td>
      <td>
      $cdXML.PRICE.text </td>
      <td>
      $cdXML.YEAR.text</td>
     </tr>
  #end
#end
</table>

***Pull from w3schools "CD Catalog" XML Page***

#set($myXML = $xmltool.read("https://www.w3schools.com/XML/cd_catalog.xml")) #foreach($cd in $myXML.children().iterator()) #set($cdXML = $xmltool.parse($cd)) #if($velocityCount<=5) #end #end

Title

Artist

Country

Company

Price

Year

$cdXML.TITLE.text $cdXML.ARTIST.text $cdXML.COUNTRY.text $cdXML.COMPANY.text $cdXML.PRICE.text $cdXML.YEAR.text