Re: FreeMarker for newbies

Daniel Dekany <[email protected]> Wed, 10 Jul 2013 16:58:48 +0200
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Wednesday, July 10, 2013, 12:47:23 PM, Eyal wrote:

> Hi,
>
> I'll explain in details.
>
> I want to generate an XML file, that I have some of its general structure,
> but some elements should be added in runtime.
>
> The way I understood, I can create a template for the XML elements that I
> need to calculate during runtime.
>
> The missing information for me is- How do I process the template- that the
> result will be added to the correct location in the XML file

How do you know where will those dynamic pieces inserted? If
it's know ahead of time, or at least you know where the potential
insertion points are (only they are conditional), you can create a
template from the whole XML file:

  <myXml>
    <blah />
    ${insertThoseElementsHere} or <@doSomeMoreFancyInsertingHere />
    <blah />
    ${insertSomeMoreElementsHere}
  </myXml>

So that's a typical templating task. I guess if that's what you need
you figure this out.

So, do you have to insert into a non-template XML? Or do you have to
decide where to insert what by walking the tree in Java? Then you can
invoke FreeMarker to generate a string at those places. Except... in
already parsed XML (DOM or SAX events) you can insert text. So maybe
you can get the source location of those places, and insert them into
the XML. Assuming you only need to generate XML "files" here, that's
probably the most efficient you can do, I think.

-- 
Thanks,
 Daniel Dekany


------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk