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
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="SmooksBigFile" startOnLoad="true" transports="vfs" xmlns="http://ws.apache.org/ns/synapse";>
    <target>
        <inSequence>
            <log level="custom">
                <property name="property_name" value="&quot;Inside FlatFile ***************************************** &quot;"/>
            </log>
            <property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
            <property name="REST_URL_POSTFIX" scope="axis2" type="STRING" value=""/>
            <property action="remove" name="ClientApiNonBlocking" scope="axis2"/>
            <smooks config-key="gov:custom/smooksConfig.xml">
                <input type="xml"/>
                <output type="text"/>
            </smooks>
            <property expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.csv')" name="transport.vfs.ReplyFileName" scope="transport" type="STRING"/>
            <property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
            <property name="messageType" scope="axis2" type="STRING" value="application/csv"/>
            <property action="remove" name="LAST_MODIFIED" scope="transport"/>
            <send>
                <endpoint>
                    <address uri="vfs:file:///C:/Flatfile/output"/>
                </endpoint>
            </send>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </target>
    <parameter name="transport.vfs.Streaming">true</parameter>
    <parameter name="transport.PollInterval">50ms</parameter>
    <parameter name="transport.vfs.ContentType">application/xml</parameter>
    <parameter name="transport.vfs.FileURI">file:///C:/Flatfile/input</parameter>
    <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
    <parameter name="transport.vfs.MoveAfterFailure">file:///C:/Flatfile/failure</parameter>
    <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
    <parameter name="transport.vfs.FileNamePattern">.*\.xml</parameter>
    <parameter name="transport.vfs.Locking">disable</parameter>
    <parameter name="transport.vfs.MoveAfterProcess">file:///C:/Flatfile/orgFilesProcessedSuccessfully</parameter>
</proxy>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to