Re: XML processing : how to generate several output out of one data model
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Tuesday, January 15, 2008, 4:54:49 PM, thierry.henrio wrote:
> Hi, i'm newb and this post is long
>
> given the following xml model
>
> <connection name="sle-001">
> <property name="host" value="localhost"/>
> <property name="port" value="1234"/>
> </connection>
> <connection name="sle-002">
> <property name="host" value="localhost"/>
> <property name="port" value="1234"/>
> </connection>
> <connection name="virtual">
> <connectionRef name="sle-001"/>
> <connectionRef name="sle-002"/>
> </connection>
>
> i need to generate the following files : sle-001.xml, sle-002, virtual.xml with
> templates sle.ftl and virtual.ftl
>
> STEP1 : stone
> separatly, each <connection> xml content + appropriate template = correct output
> that is fine
>
>
> STEP2 : church
> i would like to automate this : given the whole xml data model (sle-001,
> sle-002, virtual) , i want to generate all 3 files
>
> i tried
> CLUMSY ??
> *inject template information to the model
> (for instance <connection name="sle-001" templateFile="sle.ftl">)
Wether it is clumsy or not depends on how do *you* know which template
should be used. If you just find it out from the "name" attribute,
then you might as well teach your Java program to do the same. (And
however it is, one thing is sure: FreeMarker will not be in your way
doing it the possible best way. Choosing templates and assembling the
data-model is not the duty of the templates after all.)
> *make a NodeModel out of it
>
> *visit NodeModel, and when i see a NodeModel with name and template, generate
> like in STEP1
>
> this does not work : asking model.get("name")
Don't work with NodeModel-s. Just work with W3C DOM like if there is
no FreeMarker around, and pass the W3C DOM nodes directly to
FreeMarker. At least with the default object wrapper it will wrap them
into NodeModel-s automatically. You don't even have to know about
NodeModel-s.
> causes npe on
> java.lang.NullPointerException
> at
> freemarker.template.utility.StringUtil.matchesName(StringUtil.java:1110)
> at
> freemarker.ext.dom.ElementModel.matchesName(ElementModel.java:208)
> at freemarker.ext.dom.DocumentModel.get(DocumentModel.java:87)
>
> i believe the NodeModel can not be used outside Template.process method
> execution, that is without Environment.getCurrentEnvironment()
I don't know about that, but maybe *some* functions of it will not
work... But surely, it was meant to be used during template execution.
>
> ADVICE WELCOME
> Is there a means of using freemarker to produce my STEP2 goal out of whole xml
> data file ?
>
> Regards
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
--
Best regards,
Daniel Dekany
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/