[Java]FreemarkerでXML(NodeModel)のElementの一覧を表示してみる。
- January 28th, 2010
ということで、FreemarkerでXMLの内容を表示したいときに、どんなエレメントが紐づいているのか知りたかったので、
FreemarkerのFunctionを使って表示させtみた。
<#function pprint xmlroot depth>
<#local ret>
<#list xmlroot?children as c>
<#list 0..depth as x> </#list>
<#if c?node_type = 'element'>
- ${c?node_type}
<#local d = depth + 1>
${c?node_name}
${pprint(c, d)}
</#if><br />
</#list>
</#local>
<#return ret>
</#function>
使い方はこんな感じ
${pprint(xmldoc, 0)}
Popularity: 17% [?]