You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@freemarker.apache.org by "John D. Ament" <jo...@apache.org> on 2017/01/14 23:39:12 UTC
Parsing XML Files in Freemarker templates
Hi,
I was wondering, are there any features in freemarker that would allow me
to parse an XML file and loop through its contents? This would need to be
directly within the freemarker template.
John
Re: Parsing XML Files in Freemarker templates
Posted by "John D. Ament" <jo...@apache.org>.
On Sun, Jan 15, 2017 at 5:43 AM Daniel Dekany <dd...@freemail.hu> wrote:
> Sunday, January 15, 2017, 12:39:12 AM, John D. Ament wrote:
>
> > Hi,
> >
> > I was wondering, are there any features in freemarker that would allow me
> > to parse an XML file and loop through its contents? This would need to
> be
> > directly within the freemarker template.
> >
> > John
>
> If you really have to load the XML file from the template (which is
> unusual), then write a TemplateMethodModelEx that calls
> freemarker.ext.dom.NodeModel.parse(InputSource). The result can be
> traversed as described at http://freemarker.org/docs/xgui.html.
>
> Of course, normally, you load the XML before that template is called,
> and pass the W3C DOM Node or the NodeModel to it through the
> data-model.
>
Hmm so the real reason I wanted to do it directly was to avoid adding
code. Sounds like I'd still have to make code changes. Ok. Thanks!
>
> --
> Thanks,
> Daniel Dekany
>
>
Re: Parsing XML Files in Freemarker templates
Posted by Daniel Dekany <dd...@freemail.hu>.
Sunday, January 15, 2017, 12:39:12 AM, John D. Ament wrote:
> Hi,
>
> I was wondering, are there any features in freemarker that would allow me
> to parse an XML file and loop through its contents? This would need to be
> directly within the freemarker template.
>
> John
If you really have to load the XML file from the template (which is
unusual), then write a TemplateMethodModelEx that calls
freemarker.ext.dom.NodeModel.parse(InputSource). The result can be
traversed as described at http://freemarker.org/docs/xgui.html.
Of course, normally, you load the XML before that template is called,
and pass the W3C DOM Node or the NodeModel to it through the
data-model.
--
Thanks,
Daniel Dekany