Re: [FreeMarker-user] freemarker xml/xslt functions
Generates text that depends on changing data (like dynamic HTML).
Brought to you by:
revusky
|
From: Daniel D. <dd...@fr...> - 2005-12-22 17:25:11
|
Thursday, December 22, 2005, 12:42:24 PM, Russell Simpkins wrote:
>> > public class Helper {
>> > public Document load(String xml) {
>> > File inFile= new File(xml);
>> > Document docNode = builder.parse(inFile);
>> >
>> > TemplateModel document = new NodeListModel(docNode);
>> > TemplateNodeModel docNodeModel =
>>NodeModel.wrap(docNode);
>> > HashMap root = new HashMap();
>> > root.put("document", document);
>>
>>Why do you modify the root? Just return it. It will be the value of an
>>method call expression.
>
> It was copied from the FreeMarkerXmlTask,
Not my code... :) Seriously, I believe it has some special reasons
there, like the "document" variable is reserved with predefined meaning
there.
> I wanted to make sure, that if i
> created a class that I had to rap the document in a NodeListModel.
For that you could just return the value as well... no difference.
> Is it the NodeListModel that allows the template to say stuff like
> .node.mytopnodename.mynestednodename.mynestedentity
NodeListModel is deprecated, so just forget that. You may run into it in
the FreeMarkerXmlTask, but that's only for backward compatibility. The
freemarker.ext.dom is the place for the modern wrapper. Yes, it supports
only W3C DOM.
> I've worked with Anakia, and with that you dom through the doc with
> getSibling and getNextSibling which isn't as reminder friendly.
Note that it is also possible with FM, just in case you need it.
>>Something like this. BTW the commonly used "tools" can added at the
>>Configuration level, using yourConfiguration.setSharderVariable(...).
>
> I haven't used Velocity's tools that much. I will read more on the
> configuration level.
>
> I have found that with Jaxen you can do xpath document() function to any xml
> document below the run directory. So, whereas <#assign
> loaded=.node['document("/some/other/dir/file.xml")']> will give you an
> "Unable to parse URI"
Did you tried with a full URI, like "file:/some/other/dir/file.xml"?
> , when running the FreeMarker XML task, I could so
> <#assign loaded=.node['document("xml/faq.xml")']> without issue.
> I've seen similar results with XSLT and the JDK 1.4, 1.5 XPath
> implementation. If I set up a transformer with a file, I could use
> document() to anything on the disk, but if I started the transformer with an
> input stream, I could not use anything on the disk.
Relative URL-s have to be resolved relatively to something, so if the
main document has no URL, because it comes from an InputStream... you
see. When I have this issue with SAX parsers, I used to specify a fake
System ID, like "file:/the/base/directory/__java.io.InputStream__".
--
Best regards,
Daniel Dekany
|