问题
Dabbling with WSO2 ESB example http://wso2.org/library/articles/2011/01/wso2-esb-example-file-processing but encountering a problem where when a simple csv file
name0,value0
name1,value1
name2,value2
name3,value3
is parsed by smooks using this configuration
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.1.xsd">
<csv:reader fields="name,value" />
</smooks-resource-list>
results in largely the correct output but the first line includes the payload namespace which is incorrect
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<text xmlns="http://ws.apache.org/commons/ns/payload">name0,value0
name1,value1
name2,value2
name3,value3</text>
</soapenv:Body>
</soapenv:Envelope>
so when the first name0 value is read it includes the which is also incorrect.
Smooks then converts this into
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<csv-set>
<csv-record number="1">
<name><?xml version='1.0' encoding='utf-8'?><text xmlns="http://ws.apache.org/commons/ns/payload">name0</name>
<value>value0</value>
</csv-record>
<csv-record number="2">
<name>name1</name>
<value>value1</value>
</csv-record>
<csv-record number="3">
<name>name2</name>
<value>value2</value>
</csv-record>
<csv-record number="4">
<name>name3</name>
<value>value3</text></value>
</csv-record>
</csv-set>
</soapenv:Body>
</soapenv:Envelope>
So is Smooks doing all it is asked as the input includes the the as last? However, the number of elements it understands are counted as 4 so it isn't as if the csv is supposed to have a header row. I can resolve (to a certain extent) by including a header row but then the element count is incorrect. I can resolve the end closing by just including a carriage return on the last line of csv.
How can I resolve this? I have found one other thread a year ago asking the same question but no answers.
回答1:
I have sorted this now. In my smooks tag
<smooks xmlns="http://ws.apache.org/ns/synapse" config-key="conf:/smooks-config.xml">
<input type="text"/>
<output type="xml"/>
</smooks>
I had the first input element set to xml. Changing to text solved the issue. (in the GUI editor in WSO2 it defaults to having these elements whereas the tutorial doesn't have these at all).
来源:https://stackoverflow.com/questions/13915159/wso2-esb-file-processing-example-smooks-csv-parser-first-line-includes-payload-n