Thanks that works.... Could we also generate metadata in footer like below.
*"total Price : 50.9" * which is addition of price details in above two records Expected output : ------------------------------------------- author,id,title,genre,price,publish_date,description Gambardella Matthew,bk101,XML Developer's Guide,Computer,44.95,10/1/2000,Epic1 Ralls Kim,bk102,Midnight Rain,Fantasy,5.95,12/16/2000,Epic2 *total Price = 50.9* --------------------------------------------- which is addition of price details in above two records. Please guide Thanks and Regards, Aditya On Wed, Feb 21, 2018 at 3:42 PM, Prabushi Samarakoon <[email protected]> wrote: > Hi Aditya, > > By default WSO2 Developer Studio generates the mapping javascript function > only to map input data to output data. Therefore, csv headers will not be > included in the mapping function. To retrieve csv headers at the output, > you can change the mapping function at xmlToCsv1.dmc file as follows. > Required headers were added as the first object of outputroot array. > > > map_S_catalog_S_root = function(){ > var outputroot={}; > > var count_i_book = 1; > outputroot = []; > > outputroot[0] = {}; > outputroot[0].Author = 'author'; > outputroot[0].id = 'id'; > outputroot[0].title = 'title'; > outputroot[0].genre = 'genre'; > outputroot[0].price = 'price'; > outputroot[0].publish_date = 'publish_date'; > outputroot[0].description = 'description'; > > for(i_book in inputcatalog.book){ > outputroot[count_i_book] = {}; > outputroot[count_i_book].Author = inputcatalog.book[i_book].author; > outputroot[count_i_book].id = inputcatalog.book[i_book].attr_id; > outputroot[count_i_book].title = inputcatalog.book[i_book].title; > outputroot[count_i_book].genre = inputcatalog.book[i_book].genre; > outputroot[count_i_book].price = inputcatalog.book[i_book].price; > outputroot[count_i_book].publish_date = inputcatalog.book[i_book]. > publish_date; > outputroot[count_i_book].description = inputcatalog.book[i_book]. > description; > > count_i_book++; > } > return outputroot; > }; > > > Thanks, > Prabushi > > On Wed, Feb 21, 2018 at 2:53 PM, aditya shivankar < > [email protected]> wrote: > >> Hi Sir, >> >> My issue is first line in Expected Output which contains the keys(column >> headers): >> "author,id,title,genre,price,publish_date,description" >> >> is missing in current output file. >> >> Please guide. >> >> With Regards, >> Aditya >> >> On Wed, Feb 21, 2018 at 2:15 PM, aditya shivankar < >> [email protected]> wrote: >> >>> Hi Sir, >>> >>> I am using Datamapper for transformation of input request(xml) to output >>> format(csv) . But in the output format(csv) the column headers are missing >>> . Please guide how to generate those in output file. >>> >>> 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> >>> </catalog> >>> >>> Expected Output : >>> author,id,title,genre,price,publish_date,description >>> Gambardella Matthew,bk101,XML Developer's Guide,Computer,44.95,2000-10-0 >>> 1,Epic1 >>> Ralls Kim,bk102,Midnight Rain,Fantasy,5.95,2000-12-16,Epic2 >>> >>> Current Output : >>> >>> Gambardella, Matthew,bk101,XML Developer's Guide,Computer,44.95,2000-10-0 >>> 1,Epic1 >>> Ralls, Kim,bk102,Midnight Rain,Fantasy,5.95,2000-12-16,Epic2 >>> >>> proxy service : >>> >>> <?xml version="1.0" encoding="UTF-8"?> >>> <proxy name="StockQuoteProxy" startOnLoad="true" transports="vfs" xmlns=" >>> http://ws.apache.org/ns/synapse"> >>> <target> >>> <inSequence> >>> <log level="full"> >>> <property name="property_name" value="Read from file >>> -----------------------"/> >>> </log> >>> <datamapper config="gov:datamapper/xmlToCsv1.dmc" >>> inputSchema="gov:datamapper/xmlToCsv1_inputSchema.json" inputType="XML" >>> outputSchema="gov:datamapper/xmlToCsv1_outputSchema.json" >>> outputType="CSV"/> >>> <log level="full"> >>> <property name="property_name" value="after enrich >>> -----------------------"/> >>> </log> >>> <property expression="fn:concat(fn:subst >>> ring-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"/> >>> <send> >>> <endpoint> >>> <address uri="vfs:file:///C:/Flatfile/output"/> >>> </endpoint> >>> </send> >>> </inSequence> >>> <outSequence/> >>> <faultSequence/> >>> </target> >>> <parameter name="transport.PollInterval">15</parameter> >>> <parameter name="transport.vfs.FileURI">f >>> ile:///C:/Flatfile/input</parameter> >>> <parameter name="transport.vfs.ContentTyp >>> e">application/xml</parameter> >>> <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter> >>> <parameter name="transport.vfs.MoveAfterF >>> ailure">file:///C:/Flatfile/failure</parameter> >>> <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter> >>> <parameter name="transport.vfs.FileNamePattern">.*\.xml</parameter> >>> <parameter name="transport.vfs.MoveAfterP >>> rocess">file:///C:/Flatfile/orgFilesProcessedSuccessfully</parameter> >>> </proxy> >>> >>> >>> Please find attachments for datamapper. >>> Please guide. >>> >>> Thanks and 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
