File 使用mulesoft解析XML文件
我试图解析从磁盘读取的一个简单XMl文件,并将其转换为JSON,然后使用Mulesoft将其存储回一个文件 这就是mule flow.xml的样子File 使用mulesoft解析XML文件,file,parsing,mule,File,Parsing,Mule,我试图解析从磁盘读取的一个简单XMl文件,并将其转换为JSON,然后使用Mulesoft将其存储回一个文件 这就是mule flow.xml的样子 <file:connector name="File" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/> <file:connector name="File1" outputPattern="sample1.tx
<file:connector name="File" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/>
<file:connector name="File1" outputPattern="sample1.txt" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/>
<flow name="datatranformerFlow">
<file:inbound-endpoint path="C:\Madhu" name="sample.xml" responseTimeout="10000" doc:name="File" connector-ref="File"/>
<file:file-to-string-transformer mimeType="application/xml" doc:name="File to String"/>
<splitter expression="#[xpath3('/Names/Name')]" doc:name="Splitter"/>
<json:xml-to-json-transformer doc:name="XML to JSON"/>
<file:outbound-endpoint path="C:\Madhu\GV dev documents\WD files" connector-ref="File1" responseTimeout="10000" doc:name="File"/>
</flow>
<Names>
<Name>
<title>bnbnbha</title>
<firstname>aa</firstname>
<lastname>aaa</lastname>
</Name>
<Name>
<title>bjkjkjk</title>
<firstname>bb</firstname>
<lastname>bbb</lastname>
</Name>
<Name>
<title>hjhjhc</title>
<firstname>cc</firstname>
<lastname>ccc</lastname>
</Name>
<Name>
<title>djkjkj</title>
<firstname>dd</firstname>
<lastname>ddd</lastname>
</Name>
</Names>
我试图解析的示例xml文件如下所示
<file:connector name="File" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/>
<file:connector name="File1" outputPattern="sample1.txt" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/>
<flow name="datatranformerFlow">
<file:inbound-endpoint path="C:\Madhu" name="sample.xml" responseTimeout="10000" doc:name="File" connector-ref="File"/>
<file:file-to-string-transformer mimeType="application/xml" doc:name="File to String"/>
<splitter expression="#[xpath3('/Names/Name')]" doc:name="Splitter"/>
<json:xml-to-json-transformer doc:name="XML to JSON"/>
<file:outbound-endpoint path="C:\Madhu\GV dev documents\WD files" connector-ref="File1" responseTimeout="10000" doc:name="File"/>
</flow>
<Names>
<Name>
<title>bnbnbha</title>
<firstname>aa</firstname>
<lastname>aaa</lastname>
</Name>
<Name>
<title>bjkjkjk</title>
<firstname>bb</firstname>
<lastname>bbb</lastname>
</Name>
<Name>
<title>hjhjhc</title>
<firstname>cc</firstname>
<lastname>ccc</lastname>
</Name>
<Name>
<title>djkjkj</title>
<firstname>dd</firstname>
<lastname>ddd</lastname>
</Name>
</Names>
BNBHA
aa
aaa
bjkjk
bb
bbb
HJHC
复写的副本
ccc
djkjkj
dd
ddd
当我运行mule项目时,我遇到了一个异常
INFO 2016-07-29 11:56:25287[[DataTransformer].File.receiver.01]org.mule.transport.File.FileMessageReceiver:在文件C:\Madhu\sample.xml上获得锁
INFO 2016-07-29 11:56:26193[[DataTransformer].DataTransformerFlow.stage1.02]org.mule.routing.ExpressionSpliter:表达式的计算结果不是可拆分的类型:java.lang.String
错误:prolog中的意外字符“b”(代码98);需要“如果您的目的只是读取XML文件,请将其转换为JSON,并将其存储到文件(无需进一步处理),然后删除文件到字符串转换器和拆分器流控件,是否可以使用#[xpath3(“/Names”)] 所以你会变成这样:
<flow name="datatranformerFlow">
<file:inbound-endpoint path="C:\Madhu" name="sample.xml" responseTimeout="10000" doc:name="File" connector-ref="File"/>
<json:xml-to-json-transformer doc:name="XML to JSON"/>
<file:outbound-endpoint path="C:\Madhu\GV dev documents\WD files" connector-ref="File1" responseTimeout="10000" doc:name="File"/>
</flow>
只需删除拆分器表达式,如您所述,您只需将此文件转换为csv,请检查以下流程:
有很多方法可以做到这一点