title: Parse map of strings and transform to xml
body: <p>Giving a map of id and string paths, i need to parse and build an xml doc.</p>
  
  <p>1) Here is the map of paths with ids (collected from database): </p>
  
  <pre><code>def trees = [:]
  trees.put(1,"TEST/folder1")
  trees.put(2,"TEST/folder2")
  trees.put(3,"TEST/folder1/folder1.1")
  trees.put(4,"TEST/folder2/folder2.1/folder2.1.2")
  trees.put(5,"TEST/folder1/folder1.2") 
  trees.put(6,"TEST/folder1/folder1.2/folder1.2.1/")                        
  trees.put(7,"TEST/folder1/folder1.2/folder1.2.2/")
  trees.put(8,"TEST/folder1/folder1.2/folder1.2.2/1.2.2.1")       
  </code></pre>
  
  <p>2) Closure definition</p>
  
  <pre><code>def parseTreeNodes(HashMap&lt;Integer,String&gt; t) {
      def treeNodes = [:]
      def nodeItems = []
      def subItems=[]
      t.each { k,v -&gt;
          subItems = v.split('/')
          subItems.eachWithIndex { node,i -&gt;
              if(!treeNodes.values().contains(node)) {
                  treeNodes.put(id:k,[depth:i,node:node,parent:subItems[i-1]])
              }
          }
      }
      println treeNodes.toString() + "---"
  }
  </code></pre>
  
  <p>3) Call the closure</p>
  
  <pre><code>parseTreeNodes(trees)
  </code></pre>
  
  <p>How to apply an xml transform to this filter so as to get an xml doc as output whithout duplicates?</p>
  
  <p>4) Is there a groovy way to convert the xml tree to get attributes with name and id (extracted from the first iteration) ???</p>
  
  <pre><code>&lt;folder name="folder1" id="1" depth="1"&gt;
        &lt;folder name="folder1.2" id="2" path="folder1/folder1.2" depth="2"/&gt;
   &lt;folder&gt; 
  ...
  </code></pre>
  
  <p>In fact, the following map has already all the datas:</p>
  
  <pre><code>def treeNodes = [:]
       trees.each { k,v -&gt;
                      subItems = v.split('/')
                      subItems.eachWithIndex { node,i -&gt;
                          if(!treeNodes.values().contains(node)) {
                              treeNodes.put(id:k,[depth:i,node:node,parent:subItems[i-1]])
                          }
                      }
                  }
  </code></pre>