Hi Aditya,

It seems the error is coming from the smooks configuration. When I removed
the xml namespace from the smooksConfig as follows, I was able to retrieve
the csv content as a text output. "catalog" tag remains in the output,
since only the "book" tag is transformed according to the template.

*smooksConfig.xml*

<?xml version="1.0" encoding="UTF-8"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd";
    xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd";>
    <params>
        <param name="stream.filter.type">SAX</param>
       <!-- <param name="inputType">input.xml</param>
         <param name="input.xml"
type="input.type.actived">File:/C:\Work\2016\09_ESB_Auto_Mail_rpts\TestFiles\TestFileXMLCSVMap.xml
        </param>  -->
        <param name="default.serialization.on">true</param>
    </params>
    <resource-config selector="catalog,book">
        <resource>org.milyn.delivery.DomModelCreator</resource>
    </resource-config>
    <ftl:freemarker applyOnElement="book">
        <ftl:template>
            <!--
${.vars["book"].author},${.vars["book"].title},${.vars["book"].genre} -->
        </ftl:template>
        <param name="quote">"</param>
        <param name="includeFieldNames">true</param>
        <param name="csvFields">author,title,genre</param>
        <param name="seperator">,</param>
        <param name="messageType">CSV</param>
        <param name="templateDataProvider">input</param>
    </ftl:freemarker>
</smooks-resource-list>

*Output*

<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="
http://schemas.xmlsoap.org/soap/envelope/";><soapenv:Body><ax:text xmlns:ax="
http://ws.apache.org/commons/ns/payload";>&lt;catalog>

             Gambardella Matthew,XML Developer's Guide,Computer


             Ralls Kim,Midnight Rain,Fantasy

             Gambardella Matthew,XML Developer's Guide,Computer


             Ralls Kim,Midnight Rain,Fantasy

&lt;/catalog></ax:text></soapenv:Body></soapenv:Envelope>


Thanks,
Prabushi

On Thu, Mar 15, 2018 at 3:09 PM, aditya shivankar <
[email protected]> wrote:

> Subject : Smooks mediator XML TO CSV conversion. Please guide.
>
> Respected Sir,
>
> I am reading a xml file using vfs, converting it into csv, then writing it
> to another file.
> Trying to use smooks mediator for converting xml data to csv.
> Using Smooks mediator as I am trying to process very large files.
>
> Sample Input :
>
> <?xml version="1.0"?>
> <catalog>
>    <book id="bk101">
>       <author>Gambardella Matthew</author>
>       <title>XML Developer's Guide</title>
>       <genre>Computer</genre>
>       <price>44.95</price>
>       <publish_date>2000-10-01</publish_date>
>       <description>Epic1</description>
>    </book>
>    <book id="bk102">
>       <author>Ralls Kim</author>
>       <title>Midnight Rain</title>
>       <genre>Fantasy</genre>
>       <price>5.95</price>
>       <publish_date>2000-12-16</publish_date>
>       <description>Epic2</description>
>    </book>
> <book id="bk101">
>       <author>Gambardella Matthew</author>
>       <title>XML Developer's Guide</title>
>       <genre>Computer</genre>
>       <price>44.95</price>
>       <publish_date>2000-10-01</publish_date>
>       <description>Epic1</description>
>    </book>
>    <book id="bk102">
>       <author>Ralls Kim</author>
>       <title>Midnight Rain</title>
>       <genre>Fantasy</genre>
>       <price>5.95</price>
>       <publish_date>2000-12-16</publish_date>
>       <description>Epic2</description>
>    </book>
> </catalog>
>
> Expected output :
>
> author,id,title,genre,price,publish_date,description
> Gambardella Matthew,bk101,XML Developer's Guide,Computer,44.95,2000-10-
> 01,Epic1
> Ralls Kim,bk102,Midnight Rain,Fantasy,5.95,2000-12-16,Epic2
> Gambardella Matthew,bk101,XML Developer's Guide,Computer,44.95,2000-10-
> 01,Epic1
> Ralls Kim,bk102,Midnight Rain,Fantasy,5.95,2000-12-16,Epic2
> Number of Records :4, TotalPrice : 101.8
>
>
>
> smooksConfig I am trying :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd";
>     xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd";>
>     <params>
>         <param name="stream.filter.type">SAX</param>
>        <!-- <param name="inputType">input.xml</param>
>          <param name="input.xml" type="input.type.actived">
> File:/C:\Work\2016\09_ESB_Auto_Mail_rpts\TestFiles\TestFileXMLCSVMap.xml
>         </param>  -->
>         <param name="default.serialization.on">true</param>
>     </params>
>     <resource-config selector="catalog,book">
>         <resource>org.milyn.delivery.DomModelCreator</resource>
>     </resource-config>
>     <ftl:freemarker applyOnElement="book">
>         <ftl:template>
>             <!-- <#ftl ns_prefixes={"D":"http://ws.apache.org/ns/synapse"}>
> ${.vars["book"].author},${.vars["book"].title},${.vars["book"].genre} -->
>         </ftl:template>
>         <param name="quote">"</param>
>         <param name="includeFieldNames">true</param>
>         <param name="csvFields">author,title,genre</param>
>         <param name="seperator">,</param>
>         <param name="messageType">CSV</param>
>         <param name="templateDataProvider">input</param>
>     </ftl:freemarker>
> </smooks-resource-list>
>
> Error I am getting :
>
> [2018-03-15 13:24:49,417] [EI-Core]  INFO - LogMediator property_name =
> "Inside FlatFile ***************************************** "
> [2018-03-15 13:24:50,225] [EI-Core] ERROR - runtime
>
> Error on line 2, column 75 in free-marker-template
> Expecting a string, date or number here, Expression .vars["book"].author
> is instead a freemarker.ext.dom.NodeListModel
> The problematic instruction:
> ----------
> ==> ${.vars["book"].author} [on line 2, column 73 in free-marker-template]
> ----------
>
> Java backtrace for programmers:
> ----------
> freemarker.core.NonStringException: Error on line 2, column 75 in
> free-marker-template
> Expecting a string, date or number here, Expression .vars["book"].author
> is instead a freemarker.ext.dom.NodeListModel
>
> With Regards,
> Aditya
>
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
*Prabushi Samarakoon*
Software Engineer
Mobile: +94715434580
Email: [email protected]
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to