Note that there are some explanatory texts on larger screens.

plurals
  1. POtree sorting in groovy
    primarykey
    data
    text
    <p>Giving a LinkedHashMap, i' m trying fo build a full xml tree in groovy.</p> <p>1) the map:</p> <pre><code>def trees = [:] trees.put(1,[id:'1',path:'ROOT/folder1',name:'folder1',isFolder:'true']) trees.put(2,[id:'2',path:'ROOT/folder1/folder1.1',name:'folder1.1',isFolder:'true']) trees.put(3,[id:'3',path:'ROOT/folder1/folder1.1/folder1.1.1',name:'folder1.1.1',isFolder:'true']) trees.put(4,[id:'4',path:'ROOT/folder2',name:'folder2',isFolder:'true']) trees.put(5,[id:'5',path:'ROOT/folder3',name:'folder3',isFolder:'true']) trees.put(6,[id:'6',path:'ROOT/folder3/folder3.1',name:'folder3.1',isFolder:'true']) </code></pre> <p>2) Sort Tree closure:</p> <pre><code>//def rslt = { [:].withDefault{ owner.call() } } def a = [] def rslt = { [:].withDefault{ owner.call() } }().with { t -&gt; trees.each { k, v -&gt; v.path.tokenize( '/' ).inject( t ) { tr, i -&gt; tr[ i ] } } return t } </code></pre> <p>3) how to build an Xml doc, with xml slurper for instance,</p> <p>a model would be like this:</p> <pre><code>&lt;ROOT&gt; &lt;folder1 name="folder1" id="1" parent="ROOT" depth="1" path="ROOT/folder1"&gt; &lt;folder1.1 name="folder1.1" id="2" parent="folder1" depth="2" path="ROOT/folder1/folder1.1"&gt; &lt;folder1.1.1 name="folder1.1.1" id="3" parent="folder1.1" depth="3" path="ROOT/folder1.1/folder1.1.1"/&gt; &lt;/folder1.1&gt; &lt;/folder1&gt; ... &lt;/ROOT&gt; </code></pre> <p>looking for a closure using sthg like groovy.xml.MarkupBuilder(sw).with {</p> <p>Any idea or suggestions ?</p> <p>BR.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload