I am trying to convert a simple XML file to a CSV file, that part has gone perfectly when using an online tool that show you the output.
When I run the file through the code using a java based integration software, it throws an error; Caused by: org.xml.sax.SAXParseException: Premature end of file.
Below I have included the Input XML, XSLT and output(I'm sure showing the output isn't necessary here)
I used an example XML to CSV as a reference, the output was good, I removed a few of unnecessary elements/tags which didn't change the desired result
Input:
<?xml version="1.0" encoding="UTF-8"?>
<Results>
<Row>
<soldto>000999900</soldto>
<namelong>long name of company</namelong>
<postcode>po3stc0d3</postcode>
<AltVendDesc>some company name</AltVendDesc>
<prodcode>09060170</prodcode>
<proddescription>productdescriptionhere</proddescription>
<billingdoc>0099999990</billingdoc>
<bdate>20190905</bdate>
<invqty>12</invqty>
<CustPrice>7.3700</CustPrice>
<Gross_inc.batchcharge_>88.4400</Gross_inc.batchcharge_>
<VenProdCode>AA1234</VenProdCode>
</Row>
</Results>
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<?xml-stylesheet type="text/xsl"?>
<xsl:output method="text"/>
<xsl:variable name="delimiter" select="','"/>
<xsl:template match="/">
<tr>
<th style="text-align:Left">soldto</th>
<xsl:value-of select="$delimiter"/>
<th style="text-align:Left">namelong</th>
<xsl:value-of select="$delimiter"/>
<th style="text-align:Left">postcode</th>
<xsl:value-of select="$delimiter"/>
<th style="text-align:Left">AltVendDesc</th>
<xsl:value-of select="$delimiter"/>
<th style="text-align:Left">prodcode</th>
<xsl:value-of select="$delimiter"/>
<th style="text-align:Left">proddescription</th>
<xsl:value-of select="$delimiter"/>
<th style="text-align:Left">billingdoc</th>
<xsl:value-of select="$delimiter"/>
<th style="text-align:Left">bdate</th>
<xsl:value-of select="$delimiter"/>
<th style="text-align:Left">invqty</th>
<xsl:value-of select="$delimiter"/>
<th style="text-align:Left">CustPrice</th>
<xsl:value-of select="$delimiter"/>
<th style="text-align:Left">Gross_inc.batchcharge_</th>
<xsl:value-of select="$delimiter"/>
<th style="text-align:Left">VenProdCode</th>
<xsl:text>
</xsl:text>
</tr>
<xsl:for-each select="Results/Row">
<tr>
<td>
<xsl:value-of select="soldto"/>
<xsl:value-of select="$delimiter"/>
</td>
<td>
<xsl:value-of select="namelong"/>
<xsl:value-of select="$delimiter"/>
</td>
<td>
<xsl:value-of select="postcode"/>
<xsl:value-of select="$delimiter"/>
</td>
<td>
<xsl:value-of select="AltVendDesc"/>
<xsl:value-of select="$delimiter"/>
</td>
<td>
<xsl:value-of select="prodcode"/>
<xsl:value-of select="$delimiter"/>
</td>
<td>
<xsl:value-of select="proddescription"/>
<xsl:value-of select="$delimiter"/>
</td>
<td>
<xsl:value-of select="billingdoc"/>
<xsl:value-of select="$delimiter"/>
</td>
<td>
<xsl:value-of select="bdate"/>
<xsl:value-of select="$delimiter"/>
</td>
<td>
<xsl:value-of select="invqty"/>
<xsl:value-of select="$delimiter"/>
</td>
<td>
<xsl:value-of select="CustPrice"/>
<xsl:value-of select="$delimiter"/>
</td>
<td>
<xsl:value-of select="Gross_inc.batchcharge_"/>
<xsl:value-of select="$delimiter"/>
</td>
<td>
<xsl:value-of select="VenProdCode"/>
</td>
<xsl:text>
</xsl:text>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Output is:
soldto,namelong,postcode,AltVendDesc,prodcode,proddescription,billingdoc,bdate,invqty,CustPrice,Gross_inc.batchcharge_,VenProdCode
000999900,long name of company,po3stc0d3,some company name,09060170,productdescriptionhere,0099999990,20190905,12,7.3700,88.4400,AA1234
Stack trace:
2019-09-06T10:39:35,584 DEBUG [Transform_customer_Data@Consume from database] [com.adaptris.core.StandardWorkflow] handling bad message
2019-09-06T10:39:35,585 DEBUG [Transform_customer_Data@Consume from database] [com.adaptris.core.FixedIntervalPoller] time to process [1] messages [8] ms
2019-09-06T10:39:55,587 DEBUG [Transform_customer_Data@Consume from database] [com.adaptris.core.StandardWorkflow] start processing msg [DefaultAdaptrisMessageImp[uniqueId=5225a706-fe60-433b-9b42-dccc1f5f4673,metadata=[]]]
2019-09-06T10:39:55,588 DEBUG [Transform_customer_Data@Consume from database] [com.adaptris.core.ServiceList] Executing doService on [XmlTransformService(Transform_Data)]
2019-09-06T10:39:55,589 DEBUG [Transform_customer_Data@Consume from database] [com.adaptris.core.transform.XmlTransformService] using URL [./XSLT/transform.XSLT]
2019-09-06T10:39:55,591 ERROR [Transform_customer_Data@Consume from database] [com.adaptris.core.StandardWorkflow] Exception from ServiceCollection
com.adaptris.core.ServiceException: failed to transform message
at com.adaptris.core.transform.XmlTransformService.doTransform(XmlTransformService.java:190) ~[interlok-core.jar!/:3.9.0-RELEASE]
at com.adaptris.core.transform.XmlTransformService.doService(XmlTransformService.java:127) ~[interlok-core.jar!/:3.9.0-RELEASE]
at com.adaptris.core.ServiceList.applyServices(ServiceList.java:99) ~[interlok-core.jar!/:3.9.0-RELEASE]
at com.adaptris.core.ServiceCollectionImp.doService(ServiceCollectionImp.java:198) ~[interlok-core.jar!/:3.9.0-RELEASE]
at com.adaptris.core.StandardWorkflow.handleMessage(StandardWorkflow.java:90) [interlok-core.jar!/:3.9.0-RELEASE]
at com.adaptris.core.StandardWorkflow.onAdaptrisMessage(StandardWorkflow.java:66) [interlok-core.jar!/:3.9.0-RELEASE]
at com.adaptris.core.PollingTrigger.processMessages(PollingTrigger.java:91) [interlok-core.jar!/:3.9.0-RELEASE]
at com.adaptris.core.PollerImp.processMessages(PollerImp.java:74) [interlok-core.jar!/:3.9.0-RELEASE]
at com.adaptris.core.FixedIntervalPoller$PollerTask.run(FixedIntervalPoller.java:60) [interlok-core.jar!/:3.9.0-RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_211]
at java.util.concurrent.FutureTask.runAndReset(Unknown Source) [?:1.8.0_211]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source) [?:1.8.0_211]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [?:1.8.0_211]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_211]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_211]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
Caused by: org.xml.sax.SAXParseException: Premature end of file.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) ~[xercesImpl.jar!/:?]
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) ~[xercesImpl.jar!/:?]
at com.adaptris.util.text.xml.XmlTransformer.createSource(XmlTransformer.java:161) ~[interlok-core.jar!/:3.9.0-RELEASE]
at com.adaptris.util.text.xml.XmlTransformer.createSource(XmlTransformer.java:153) ~[interlok-core.jar!/:3.9.0-RELEASE]
at com.adaptris.util.text.xml.XmlTransformer.transform(XmlTransformer.java:95) ~[interlok-core.jar!/:3.9.0-RELEASE]
at com.adaptris.core.transform.XmlTransformService.doTransform(XmlTransformService.java:184) ~[interlok-core.jar!/:3.9.0-RELEASE]
Which as I said earlier is fine, but when passed through the integration tool that uses java I get an exception error.
The input file cannot be change unfortunately.
Update: quotation mark was an error when attempting to post my code, it has been update.
Stack trace added
修复它:问题是使用者没有获取文件,因此它实际上什么也没做,而是试图对其进行转换。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.