xref: /aosp_15_r20/external/apache-velocity-engine/velocity-engine-examples/src/main/resources/xml.vm (revision 6626518d3d1a3a4cd21045b7974855fd6a3e2103)
1*6626518dSAndrew Vuong## Licensed to the Apache Software Foundation (ASF) under one
2*6626518dSAndrew Vuong## or more contributor license agreements.  See the NOTICE file
3*6626518dSAndrew Vuong## distributed with this work for additional information
4*6626518dSAndrew Vuong## regarding copyright ownership.  The ASF licenses this file
5*6626518dSAndrew Vuong## to you under the Apache License, Version 2.0 (the
6*6626518dSAndrew Vuong## "License"); you may not use this file except in compliance
7*6626518dSAndrew Vuong## with the License.  You may obtain a copy of the License at
8*6626518dSAndrew Vuong##
9*6626518dSAndrew Vuong##   http://www.apache.org/licenses/LICENSE-2.0
10*6626518dSAndrew Vuong##
11*6626518dSAndrew Vuong## Unless required by applicable law or agreed to in writing,
12*6626518dSAndrew Vuong## software distributed under the License is distributed on an
13*6626518dSAndrew Vuong## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14*6626518dSAndrew Vuong## KIND, either express or implied.  See the License for the
15*6626518dSAndrew Vuong## specific language governing permissions and limitations
16*6626518dSAndrew Vuong## under the License.
17*6626518dSAndrew Vuong#macro ( recursive $e $indent )
18*6626518dSAndrew Vuong#if( $e.getChildren().size() > 0 )
19*6626518dSAndrew Vuong$indent <$e.getName()>
20*6626518dSAndrew Vuong#foreach ($child in $e.getChildren() )
21*6626518dSAndrew Vuong#recursive( $child "$indent  " )
22*6626518dSAndrew Vuong#end
23*6626518dSAndrew Vuong$indent </$e.getName()>
24*6626518dSAndrew Vuong#else
25*6626518dSAndrew Vuong$indent <$e.getName()>
26*6626518dSAndrew Vuong$indent    $e.getTextTrim()
27*6626518dSAndrew Vuong$indent </$e.getName()>
28*6626518dSAndrew Vuong#end
29*6626518dSAndrew Vuong#end
30*6626518dSAndrew Vuong
31*6626518dSAndrew Vuong#set($i = " ")
32*6626518dSAndrew Vuong
33*6626518dSAndrew VuongFirst, we print out the document tree with a
34*6626518dSAndrew Vuongrecursive Velocimacro :
35*6626518dSAndrew Vuong
36*6626518dSAndrew Vuong#recursive( $root.getRootElement() $i )
37*6626518dSAndrew Vuong
38*6626518dSAndrew Vuong
39*6626518dSAndrew VuongNext, we access pieces of data directly :
40*6626518dSAndrew Vuong
41*6626518dSAndrew Vuongemail : $root.getRootElement().getChild("properties").getChild("author").getChild("email").getText()
42*6626518dSAndrew Vuonglast name :  $root.getRootElement().getChild("properties").getChild("author").getChild("name").getChild("last").getChild("full").getText()
43