File: xml.vm

package info (click to toggle)
velocity 1.3.1-2
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 4,164 kB
  • ctags: 2,922
  • sloc: java: 24,134; xml: 16,911; sh: 99; lisp: 53; makefile: 45
file content (26 lines) | stat: -rw-r--r-- 702 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#macro ( recursive $e $indent )     
#if( $e.getChildren().size() > 0 )
$indent <$e.getName()> 
#foreach ($child in $e.getChildren() ) 
#recursive( $child "$indent  " )
#end
$indent </$e.getName()>
#else
$indent <$e.getName()>
$indent    $e.getTextTrim()
$indent </$e.getName()>
#end
#end

#set($i = " ")

First, we print out the document tree with a 
recursive Velocimacro :

#recursive( $root.getRootElement() $i )


Next, we access pieces of data directly :

email : $root.getRootElement().getChild("properties").getChild("author").getChild("email").getText()
last name :  $root.getRootElement().getChild("properties").getChild("author").getChild("name").getChild("last").getChild("full").getText()