Quantcast

Beginner question: Accessing XML-Attributes via Template?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Beginner question: Accessing XML-Attributes via Template?

Tarik M.
Hello everybody,

I'm trying to parse a XML-Document with Freemarker and to merge the
model with a template, especially accessing the XML-Attributes from the
model.  I have done the following:

--------------------- code
Map<String, Object> root = new HashMap<String, Object>();
root.put("doc", freemarker.ext.dom.NodeModel.parse(new File("file.xml")));
--------------------- code

The XML-document looks like as follows:

--------------------- code
<?xml version="1.0" encoding="UTF-8"?>
<bdd:bWorkflow xsi:schemaLocation="..." xmlns:bdd="..." xmlns:xsi="...">
    <bdd:wsbpelEngineInformation wsbpelProcess="..."
wsbpelProcesslocation="...">
        <bdd:versioning version="..."/>
        <bdd:persistence storePersistent="..."/>
        <bdd:partnerLinks>
            <bdd:partnerLink name="...">
                <bdd:myRole>
                    <bdd:endpointReference
                        serviceName="..."
                        servicePort="..."
                        binding="..."
                        xmlns:pal="..."/>
                </bdd:myRole>
            </bdd:partnerLink>
            <bdd:partnerLink name="...">
                <bdd:partnerRole bdd:serviceType="..."
bdd:serviceCall="..."/>
            </bdd:partnerLink>
        </bdd:partnerLinks>
        <bdd:extensions/>
        <bdd:references>
            <bdd:reference location="..." referenceGroup="..."
namespace="..."/>
            <bdd:reference location="..." referenceGroup="..."
namespace="..."/>
        </bdd:references>
    </bdd:wsbpelEngineInformation>
</bdd:bWorkflow>
--------------------- code

Now my question: How can I access the XML-Attribute elements in the
Template? For example how to get the version-Attribute of the
versioning-Element etc?

Thanks in advance.

Kind regards.
Tarik

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Beginner question: Accessing XML-Attributes via Template?

d.lopez
Hi,

The first place you can go to see how to handle XML content from a
FreeMarker template is the manual itself ->
Part III.  XML Processing Guide:
http://freemarker.sourceforge.net/docs/xgui.html

Then you can see a working example like the one we have through FishEye:
A sample XML document:
http://fisheye5.cenqua.com/browse/webleaftest/src-www/WEB-INF/xml/showItems.xml?r=1.2
The FreeMarker template:
http://fisheye5.cenqua.com/browse/webleaftest/src-www/WEB-INF/templates/item.ftl?r=1.2
The resulting HTML:
http://fisheye5.cenqua.com/browse/webleaftest/src-www/showItems.html?r=1.4

S!
D.

Tarik Mustafic escribió:

> Hello everybody,
>
> I'm trying to parse a XML-Document with Freemarker and to merge the
> model with a template, especially accessing the XML-Attributes from the
> model.  I have done the following:
>
> --------------------- code
> Map<String, Object> root = new HashMap<String, Object>();
> root.put("doc", freemarker.ext.dom.NodeModel.parse(new File("file.xml")));
> --------------------- code
>
> The XML-document looks like as follows:
>
> --------------------- code
> <?xml version="1.0" encoding="UTF-8"?>
> <bdd:bWorkflow xsi:schemaLocation="..." xmlns:bdd="..." xmlns:xsi="...">
>     <bdd:wsbpelEngineInformation wsbpelProcess="..."
> wsbpelProcesslocation="...">
>         <bdd:versioning version="..."/>
>         <bdd:persistence storePersistent="..."/>
>         <bdd:partnerLinks>
>             <bdd:partnerLink name="...">
>                 <bdd:myRole>
>                     <bdd:endpointReference
>                         serviceName="..."
>                         servicePort="..."
>                         binding="..."
>                         xmlns:pal="..."/>
>                 </bdd:myRole>
>             </bdd:partnerLink>
>             <bdd:partnerLink name="...">
>                 <bdd:partnerRole bdd:serviceType="..."
> bdd:serviceCall="..."/>
>             </bdd:partnerLink>
>         </bdd:partnerLinks>
>         <bdd:extensions/>
>         <bdd:references>
>             <bdd:reference location="..." referenceGroup="..."
> namespace="..."/>
>             <bdd:reference location="..." referenceGroup="..."
> namespace="..."/>
>         </bdd:references>
>     </bdd:wsbpelEngineInformation>
> </bdd:bWorkflow>
> --------------------- code
>
> Now my question: How can I access the XML-Attribute elements in the
> Template? For example how to get the version-Attribute of the
> versioning-Element etc?
>
> Thanks in advance.
>
> Kind regards.
> Tarik


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Beginner question: Accessing XML-Attributes via Template?

Tarik M.
Hello,

thanks a lot for the example. I read the tutorial several times, but I wasn't able to navigate through my XML-Document hierarchy. Whatever I've tried I got the following Exception:

Expecting a string, date or number here, Expression bdd.bisgridWorkflow.wsbpelEngineInformation.@wsbpelProcess is instead a freemarker.ext.dom.NodeListModel

In the template I defined:
<process name="${doc.bWorkflow.wsbpelEngineInformation.@wsbpelProcess}">

Here is the XML part:
<bdd:bWorkflow xsi:schemaLocation="..." xmlns:bdd="..." xmlns:xsi="...">
   <bdd:wsbpelEngineInformation wsbpelProcess="..." wsbpelProcesslocation="...">
....

I thought that this is the way to navigate through the DOM-Tree, because the tutorial examples show the same. Does anybody know what's wrong in my example?

Thanks in advance.
Tarik


Daniel Lopez-3 wrote
Hi,

The first place you can go to see how to handle XML content from a
FreeMarker template is the manual itself ->
Part III.  XML Processing Guide:
http://freemarker.sourceforge.net/docs/xgui.html

Then you can see a working example like the one we have through FishEye:
A sample XML document:
http://fisheye5.cenqua.com/browse/webleaftest/src-www/WEB-INF/xml/showItems.xml?r=1.2
The FreeMarker template:
http://fisheye5.cenqua.com/browse/webleaftest/src-www/WEB-INF/templates/item.ftl?r=1.2
The resulting HTML:
http://fisheye5.cenqua.com/browse/webleaftest/src-www/showItems.html?r=1.4

S!
D.

Tarik Mustafic escribió:
> Hello everybody,
>
> I'm trying to parse a XML-Document with Freemarker and to merge the
> model with a template, especially accessing the XML-Attributes from the
> model.  I have done the following:
>
> --------------------- code
> Map<String, Object> root = new HashMap<String, Object>();
> root.put("doc", freemarker.ext.dom.NodeModel.parse(new File("file.xml")));
> --------------------- code
>
> The XML-document looks like as follows:
>
> --------------------- code
> <?xml version="1.0" encoding="UTF-8"?>
> <bdd:bWorkflow xsi:schemaLocation="..." xmlns:bdd="..." xmlns:xsi="...">
>     <bdd:wsbpelEngineInformation wsbpelProcess="..."
> wsbpelProcesslocation="...">
>         <bdd:versioning version="..."/>
>         <bdd:persistence storePersistent="..."/>
>         <bdd:partnerLinks>
>             <bdd:partnerLink name="...">
>                 <bdd:myRole>
>                     <bdd:endpointReference
>                         serviceName="..."
>                         servicePort="..."
>                         binding="..."
>                         xmlns:pal="..."/>
>                 </bdd:myRole>
>             </bdd:partnerLink>
>             <bdd:partnerLink name="...">
>                 <bdd:partnerRole bdd:serviceType="..."
> bdd:serviceCall="..."/>
>             </bdd:partnerLink>
>         </bdd:partnerLinks>
>         <bdd:extensions/>
>         <bdd:references>
>             <bdd:reference location="..." referenceGroup="..."
> namespace="..."/>
>             <bdd:reference location="..." referenceGroup="..."
> namespace="..."/>
>         </bdd:references>
>     </bdd:wsbpelEngineInformation>
> </bdd:bWorkflow>
> --------------------- code
>
> Now my question: How can I access the XML-Attribute elements in the
> Template? For example how to get the version-Attribute of the
> versioning-Element etc?
>
> Thanks in advance.
>
> Kind regards.
> Tarik


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
FreeMarker-user mailing list
FreeMarker-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Beginner question: Accessing XML-Attributes via Template?

Daniel Dekany
Tuesday, March 24, 2009, 12:47:58 AM, Tarik M. wrote:

>
> Hello,
>
> thanks a lot for the example. I read the tutorial several times, but I
> wasn't able to navigate through my XML-Document hierarchy. Whatever I've
> tried I got the following Exception:
>
> Expecting a string, date or number here, Expression
> bdd.bisgridWorkflow.wsbpelEngineInformation.@wsbpelProcess is instead a
> freemarker.ext.dom.NodeListModel

The error message basically means that the result of your XML query
contains not exactly one node. So either you have 0 matching node, or
multiple matching nodes (try ${yourQuery?size} to find out which). In
those cases a the resulting node list can't be automatically treated
as a scalar, hence the cryptic error message.

> In the template I defined:
> <process
> name="${doc.bWorkflow.wsbpelEngineInformation.@wsbpelProcess}">
>
> Here is the XML part:
> <bdd:bWorkflow xsi:schemaLocation="..." xmlns:bdd="..." xmlns:xsi="...">
>    <bdd:wsbpelEngineInformation wsbpelProcess="..."
> wsbpelProcesslocation="...">
> ....
>
> I thought that this is the way to navigate through the DOM-Tree, because the
> tutorial examples show the same. Does anybody know what's wrong in my
> example?
>
> Thanks in advance.
> Tarik
>
>
>
> Daniel Lopez-3 wrote:
>>
>> Hi,
>>
>> The first place you can go to see how to handle XML content from a
>> FreeMarker template is the manual itself ->
>> Part III.  XML Processing Guide:
>> http://freemarker.sourceforge.net/docs/xgui.html
>>
>> Then you can see a working example like the one we have through FishEye:
>> A sample XML document:
>> http://fisheye5.cenqua.com/browse/webleaftest/src-www/WEB-INF/xml/showItems.xml?r=1.2
>> The FreeMarker template:
>> http://fisheye5.cenqua.com/browse/webleaftest/src-www/WEB-INF/templates/item.ftl?r=1.2
>> The resulting HTML:
>> http://fisheye5.cenqua.com/browse/webleaftest/src-www/showItems.html?r=1.4
>>
>> S!
>> D.
>>
>> Tarik Mustafic escribió:
>>> Hello everybody,
>>>
>>> I'm trying to parse a XML-Document with Freemarker and to merge the
>>> model with a template, especially accessing the XML-Attributes from the
>>> model.  I have done the following:
>>>
>>> --------------------- code
>>> Map<String, Object> root = new HashMap<String, Object>();
>>> root.put("doc", freemarker.ext.dom.NodeModel.parse(new
>>> File("file.xml")));
>>> --------------------- code
>>>
>>> The XML-document looks like as follows:
>>>
>>> --------------------- code
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <bdd:bWorkflow xsi:schemaLocation="..." xmlns:bdd="..." xmlns:xsi="...">
>>>     <bdd:wsbpelEngineInformation wsbpelProcess="..."
>>> wsbpelProcesslocation="...">
>>>         <bdd:versioning version="..."/>
>>>         <bdd:persistence storePersistent="..."/>
>>>         <bdd:partnerLinks>
>>>             <bdd:partnerLink name="...">
>>>                 <bdd:myRole>
>>>                     <bdd:endpointReference
>>>                         serviceName="..."
>>>                         servicePort="..."
>>>                         binding="..."
>>>                         xmlns:pal="..."/>
>>>                 </bdd:myRole>
>>>             </bdd:partnerLink>
>>>             <bdd:partnerLink name="...">
>>>                 <bdd:partnerRole bdd:serviceType="..."
>>> bdd:serviceCall="..."/>
>>>             </bdd:partnerLink>
>>>         </bdd:partnerLinks>
>>>         <bdd:extensions/>
>>>         <bdd:references>
>>>             <bdd:reference location="..." referenceGroup="..."
>>> namespace="..."/>
>>>             <bdd:reference location="..." referenceGroup="..."
>>> namespace="..."/>
>>>         </bdd:references>
>>>     </bdd:wsbpelEngineInformation>
>>> </bdd:bWorkflow>
>>> --------------------- code
>>>
>>> Now my question: How can I access the XML-Attribute elements in the
>>> Template? For example how to get the version-Attribute of the
>>> versioning-Element etc?
>>>
>>> Thanks in advance.
>>>
>>> Kind regards.
>>> Tarik
>>
>>
>> ------------------------------------------------------------------------------
>> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
>> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
>> easily build your RIAs with Flex Builder, the Eclipse(TM)based development
>> software that enables intelligent coding and step-through debugging.
>> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
>> _______________________________________________
>> FreeMarker-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>>
>>
>

--
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Beginner question: Accessing XML-Attributes via Template?

d.lopez
That Exception: "Expecting...is instead a
freemarker.ext.dom.NodeListModel" is the most common one when processing
XML with FreeMarker. If you come from an XSLT background, it takes a
while to get used to it but FreeMarker is not as lenient as XSLT is,
meaning that if a node does not exist, in XSLT usually "nothing happens"
whereas in FreeMarker, an error is produced.

And as Daniel Dekany indicated, this is usually the error that is
produced when your "XPath" does not match a Node. Instead of returning
"nothing", FreeMarker returns an empty list of nodes, hence the error
message. Given the XML, it looks as if it should match correctly one
node, but given that there are namespaces in the mix, I'm not that sure
as I have not played with "namespaced" XML with FreeMarker.

Good luck!
D.

Daniel Dekany escribió:

> Tuesday, March 24, 2009, 12:47:58 AM, Tarik M. wrote:
>> Hello,
>>
>> thanks a lot for the example. I read the tutorial several times, but I
>> wasn't able to navigate through my XML-Document hierarchy. Whatever I've
>> tried I got the following Exception:
>>
>> Expecting a string, date or number here, Expression
>> bdd.bisgridWorkflow.wsbpelEngineInformation.@wsbpelProcess is instead a
>> freemarker.ext.dom.NodeListModel
>
> The error message basically means that the result of your XML query
> contains not exactly one node. So either you have 0 matching node, or
> multiple matching nodes (try ${yourQuery?size} to find out which). In
> those cases a the resulting node list can't be automatically treated
> as a scalar, hence the cryptic error message.
>
>> In the template I defined:
>> <process
>> name="${doc.bWorkflow.wsbpelEngineInformation.@wsbpelProcess}">
>>
>> Here is the XML part:
>> <bdd:bWorkflow xsi:schemaLocation="..." xmlns:bdd="..." xmlns:xsi="...">
>>    <bdd:wsbpelEngineInformation wsbpelProcess="..."
>> wsbpelProcesslocation="...">
>> ....
>>
>> I thought that this is the way to navigate through the DOM-Tree, because the
>> tutorial examples show the same. Does anybody know what's wrong in my
>> example?
>>
>> Thanks in advance.
>> Tarik
>>
>>
>>
>> Daniel Lopez-3 wrote:
>>> Hi,
>>>
>>> The first place you can go to see how to handle XML content from a
>>> FreeMarker template is the manual itself ->
>>> Part III.  XML Processing Guide:
>>> http://freemarker.sourceforge.net/docs/xgui.html
>>>
>>> Then you can see a working example like the one we have through FishEye:
>>> A sample XML document:
>>> http://fisheye5.cenqua.com/browse/webleaftest/src-www/WEB-INF/xml/showItems.xml?r=1.2
>>> The FreeMarker template:
>>> http://fisheye5.cenqua.com/browse/webleaftest/src-www/WEB-INF/templates/item.ftl?r=1.2
>>> The resulting HTML:
>>> http://fisheye5.cenqua.com/browse/webleaftest/src-www/showItems.html?r=1.4
>>>
>>> S!
>>> D.
>>>
>>> Tarik Mustafic escribió:
>>>> Hello everybody,
>>>>
>>>> I'm trying to parse a XML-Document with Freemarker and to merge the
>>>> model with a template, especially accessing the XML-Attributes from the
>>>> model.  I have done the following:
>>>>
>>>> --------------------- code
>>>> Map<String, Object> root = new HashMap<String, Object>();
>>>> root.put("doc", freemarker.ext.dom.NodeModel.parse(new
>>>> File("file.xml")));
>>>> --------------------- code
>>>>
>>>> The XML-document looks like as follows:
>>>>
>>>> --------------------- code
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <bdd:bWorkflow xsi:schemaLocation="..." xmlns:bdd="..." xmlns:xsi="...">
>>>>     <bdd:wsbpelEngineInformation wsbpelProcess="..."
>>>> wsbpelProcesslocation="...">
>>>>         <bdd:versioning version="..."/>
>>>>         <bdd:persistence storePersistent="..."/>
>>>>         <bdd:partnerLinks>
>>>>             <bdd:partnerLink name="...">
>>>>                 <bdd:myRole>
>>>>                     <bdd:endpointReference
>>>>                         serviceName="..."
>>>>                         servicePort="..."
>>>>                         binding="..."
>>>>                         xmlns:pal="..."/>
>>>>                 </bdd:myRole>
>>>>             </bdd:partnerLink>
>>>>             <bdd:partnerLink name="...">
>>>>                 <bdd:partnerRole bdd:serviceType="..."
>>>> bdd:serviceCall="..."/>
>>>>             </bdd:partnerLink>
>>>>         </bdd:partnerLinks>
>>>>         <bdd:extensions/>
>>>>         <bdd:references>
>>>>             <bdd:reference location="..." referenceGroup="..."
>>>> namespace="..."/>
>>>>             <bdd:reference location="..." referenceGroup="..."
>>>> namespace="..."/>
>>>>         </bdd:references>
>>>>     </bdd:wsbpelEngineInformation>
>>>> </bdd:bWorkflow>
>>>> --------------------- code
>>>>
>>>> Now my question: How can I access the XML-Attribute elements in the
>>>> Template? For example how to get the version-Attribute of the
>>>> versioning-Element etc?
>>>>
>>>> Thanks in advance.
>>>>
>>>> Kind regards.
>>>> Tarik


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Beginner question: Accessing XML-Attributes via Template?

mamathayv
In reply to this post by Tarik M.
Hi all,

Even i am facing the same problem while accessing attributes from xml with namespace.
Please can any one help me.

Thanks in advance.

Regards,
Mamta
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Beginner question: Accessing XML-Attributes via Template?

Daniel Dekany
Hi,

It should be something like:

  <#ftl ns_prefixes={"e":"http://example.com/ebook"}>
  ${someElement["@e:someAttribute"]}

--
Regards,
 Daniel Dekany

Friday, May 23, 2014, 3:32:40 PM, mamathayv wrote:

> Hi all,
>
> Even i am facing the same problem while accessing attributes from xml with
> namespace.
> Please can any one help me.
>
> Thanks in advance.
>
> Regards,
> Mamta
>
>
>
>
> --
> View this message in context:
> http://freemarker.624813.n4.nabble.com/Beginner-question-Accessing-XML-Attributes-via-Template-tp626522p4655157.html
> Sent from the freemarker-user mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
> _______________________________________________
> FreeMarker-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>


------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Beginner question: Accessing XML-Attributes via Template?

gkamle
I am new to "smooks and freemarker".I want access elements in xml document.I am getting this exception while acessing xml element.I am sending my code.

Exception:-
------------

 For "${...}" content: Expected a string or something automatically convertible to string (number, date or boolean), but this evaluated to a sequence+hash (wrapper: f.e.dom.NodeListModel):
    ==> employee["first_name"]  [in template "free-marker-template" at line 1, column 84]

----
Tip: This XML query result can't be used as string because for that it had to contain exactly 1 XML node, but it contains 0 nodes. That is, the constructing XML query has found no matches.
----
----
FTL stack trace ("~" means nesting-related):
    - Failed at: ${employee["first_name"]}  [in template "free-marker-template" at line 1, column 82]

----
Java stack trace (for programmers):
----
freemarker.core.NonStringException: [... Exception message was already printed; see it above ...]
    at freemarker.core.EvalUtil.coerceModelToString(EvalUtil.java:381)
    at freemarker.core.Expression.evalAndCoerceToString(Expression.java:82)
    at freemarker.core.DollarVariable.accept(DollarVariable.java:40)
    at freemarker.core.Environment.visit(Environment.java:312)

The following are versions
java version : "1.7.0_45"
freemarker   : 2.3.22
smooks       : 1.6


javacode:-
-----------
package test;

import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.net.URI;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.milyn.Smooks;
import org.milyn.SmooksException;
import org.milyn.container.ExecutionContext;
import org.milyn.event.report.HtmlReportGenerator;
import org.milyn.io.StreamUtils;
import org.milyn.payload.StringResult;
import org.xml.sax.SAXException;


public class SmooksExample {
    public SmooksExample() {
        // TODO Auto-generated constructor stub
    }
    protected static void runSmooksNew() throws IOException, SAXException, SmooksException {

        try {
            Long stTime = System.currentTimeMillis();
            System.out.println(stTime + "==" + new Date());
            Writer xmlResultWriter = new BufferedWriter(new FileWriter(new File("C:\\Files\\SmookExample\\output_sax.dat")));
            transCustomerCSV(new File("C:\\Files\\emp_namespace.xml"), xmlResultWriter);
            Long edTime = System.currentTimeMillis();
            System.out.println(edTime + "==" + (edTime-stTime) + "===="+ new Date());
            String times = String.format("%d min, %d sec",
                    TimeUnit.MILLISECONDS.toMinutes(edTime-stTime),
                    TimeUnit.MILLISECONDS.toSeconds(edTime-stTime) -
                    TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(edTime-stTime))
                );
            System.out.println(times);
        } finally {
            //smooks.close();
        }
    }
    public static void transCustomerCSV(File csvSourceReader, Writer xmlResultWriter) throws IOException, SAXException {
        File f = new File("C:/TEMPLATES/smooks-config.xml");
        URI u = f.toURI();
        Smooks smooks = new Smooks(u.getPath());
        ExecutionContext ec = smooks.createExecutionContext();
        smooks.filterSource(ec, new StreamSource(csvSourceReader), new StreamResult(xmlResultWriter));
    }
    /**
     * @param args
     */
    public static void main(String[] args) throws IOException, SAXException, SmooksException {
        System.out.println("\n\n");
        System.out.println("==============Message In==============");
        SmooksExample.runSmooksNew();
        System.out.println("======================================\n");
    }
}


Smooks-config.xml
--------------------
<smooks-resource-list xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd" xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.3.xsd" xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.2.xsd" xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd">
  <params>
    SAX
    false
  </params>
  <core:namespaces>
    <core:namespace prefix="empl" uri="http://www.example.com/employees"/>
  </core:namespaces>
  <resource-config selector="employee,first_name">
    <resource>org.milyn.delivery.DomModelCreator</resource>
  </resource-config>
  <ftl:freemarker applyOnElement="first_name">
    <ftl:template>
    </ftl:template>
  </ftl:freemarker>
</smooks-resource-list>

sample data xml file name:  emp_namespace.xml:-
--------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<empl:employees xmlns:empl="http://www.example.com/employees">
     <empl:employee id="1">
         <empl:first_name>Bill</empl:first_name>
         <empl:last_name>Adams</empl:last_name>
         <empl:age>25</empl:age>
         <empl:hire_date>12-06-1995</empl:hire_date>
         <empl:title>Java programmer</empl:title>
        <empl:DateCreated>
            <empl:Year>1980</empl:Year>
            <empl:Month>01</empl:Month>
            <empl:Day>01</empl:Day>
        </empl:DateCreated>
        <empl:DateCompleted>
            <empl:Year>1981</empl:Year>
            <empl:Month>02</empl:Month>
            <empl:Day>02</empl:Day>
        </empl:DateCompleted>
     </empl:employee>
     <empl:employee id="2">
         <empl:first_name>Mary</empl:first_name>
         <empl:last_name>Jones</empl:last_name>
         <empl:age>32</empl:age>
         <empl:hire_date>22-09-2001</empl:hire_date>
         <empl:title>Sales manager</empl:title>
         <empl:DateCreated>
            <empl:Year>1982</empl:Year>
            <empl:Month>03</empl:Month>
            <empl:Day>03</empl:Day>
        </empl:DateCreated>
        <empl:DateCompleted>
            <empl:Year>1983</empl:Year>
            <empl:Month>04</empl:Month>
            <empl:Day>04</empl:Day>
        </empl:DateCompleted>
     </empl:employee>
</empl:employees>
Loading...