一个 XML 在 Mule 中转换为多个 XML
One XML converted into multiple XML in Mule
我有一个 xml 文件如下。
<?xml version='1.0' encoding='UTF-8'?>
<machineDetail>
<machineData>
<machineNumber>00000001</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>SCHAERER</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>REM</equipmentLocation>
<installedDate>2013-08-01T00:00:00.000+0000</installedDate>
</machineData>
<machineData>
<machineNumber>00001024</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>IBS4</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>1024</equipmentLocation>
<installedDate>2011-09-29T00:00:00.000+0000</installedDate>
</machineData>
</machineDetail>
现在我必须分成 2 xmls 具有类似
的数据
1.xml
<?xml version='1.0' encoding='UTF-8'?>
<machineDetail>
<machineData>
<machineNumber>00000001</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>SCHAERER</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>REM</equipmentLocation>
<installedDate>2013-08-01T00:00:00.000+0000</installedDate>
</machineData>
</machineDetail>
2.xml
<?xml version='1.0' encoding='UTF-8'?>
<machineDetail>
<machineData>
<machineNumber>00001024</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>IBS4</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>1024</equipmentLocation>
<installedDate>2011-09-29T00:00:00.000+0000</installedDate>
</machineData>
</machineDetail>
这必须在 Mule 中完成。请在这种情况下建议 xslt。我是 Mule 的新人。
将拆分器与 xpath MEL 表达式结合使用:像这样:
<splitter expression="#[xpath('//machineDetail/machineData')]" doc:name="Splitter"/>
这将创建两个 XML 文档,如下所示:
<machineData>
<machineNumber>00001024</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>IBS4</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>1024</equipmentLocation>
<installedDate>2011-09-29T00:00:00.000+0000</installedDate>
</machineData>
然后在拆分邮件时使用 XSLT 或类似工具将 XML 包装在
machineDetail
元素
以下流程应该可以满足您的要求。如果需要,您可能需要清理命名空间..
<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<mulexml:xslt-transformer name="xslt">
<mulexml:xslt-text>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="">
<xsl:output method="xml"/>
<xsl:template match="/">
<machineDetail>
<xsl:copy-of select="." />
</machineDetail>
</xsl:template>
</xsl:stylesheet>
</mulexml:xslt-text>
</mulexml:xslt-transformer>
</mulexml:xslt-transformer>
<file:file-to-string-transformer name="File_to_String"
doc:name="File to String" />
<flow name="testflowsFlow">
<file:inbound-endpoint path="C:\Temp\mule\in"
responseTimeout="10000" doc:name="File" />
<file:file-to-string-transformer
doc:name="File to String" />
<splitter expression="#[xpath('//machineData')]" doc:name="Splitter"
enableCorrelation="ALWAYS" />
<mulexml:dom-to-xml-transformer
doc:name="DOM to XML" />
<file:outbound-endpoint transformer-refs="xslt"
path="C:\Temp\mule\out" responseTimeout="10000" doc:name="File"
outputPattern="#[message.outboundProperties.MULE_CORRELATION_SEQUENCE].xml" />
</flow>
我有一个 xml 文件如下。
<?xml version='1.0' encoding='UTF-8'?>
<machineDetail>
<machineData>
<machineNumber>00000001</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>SCHAERER</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>REM</equipmentLocation>
<installedDate>2013-08-01T00:00:00.000+0000</installedDate>
</machineData>
<machineData>
<machineNumber>00001024</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>IBS4</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>1024</equipmentLocation>
<installedDate>2011-09-29T00:00:00.000+0000</installedDate>
</machineData>
</machineDetail>
现在我必须分成 2 xmls 具有类似
的数据1.xml
<?xml version='1.0' encoding='UTF-8'?>
<machineDetail>
<machineData>
<machineNumber>00000001</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>SCHAERER</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>REM</equipmentLocation>
<installedDate>2013-08-01T00:00:00.000+0000</installedDate>
</machineData>
</machineDetail>
2.xml
<?xml version='1.0' encoding='UTF-8'?>
<machineDetail>
<machineData>
<machineNumber>00001024</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>IBS4</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>1024</equipmentLocation>
<installedDate>2011-09-29T00:00:00.000+0000</installedDate>
</machineData>
</machineDetail>
这必须在 Mule 中完成。请在这种情况下建议 xslt。我是 Mule 的新人。
将拆分器与 xpath MEL 表达式结合使用:像这样:
<splitter expression="#[xpath('//machineDetail/machineData')]" doc:name="Splitter"/>
这将创建两个 XML 文档,如下所示:
<machineData>
<machineNumber>00001024</machineNumber>
<concessionUnitType>NONE</concessionUnitType>
<machineType>IBS4</machineType>
<customerNumber>69990005</customerNumber>
<equipmentLocation>1024</equipmentLocation>
<installedDate>2011-09-29T00:00:00.000+0000</installedDate>
</machineData>
然后在拆分邮件时使用 XSLT 或类似工具将 XML 包装在
machineDetail
元素
以下流程应该可以满足您的要求。如果需要,您可能需要清理命名空间..
<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<mulexml:xslt-transformer name="xslt">
<mulexml:xslt-text>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="">
<xsl:output method="xml"/>
<xsl:template match="/">
<machineDetail>
<xsl:copy-of select="." />
</machineDetail>
</xsl:template>
</xsl:stylesheet>
</mulexml:xslt-text>
</mulexml:xslt-transformer>
</mulexml:xslt-transformer>
<file:file-to-string-transformer name="File_to_String"
doc:name="File to String" />
<flow name="testflowsFlow">
<file:inbound-endpoint path="C:\Temp\mule\in"
responseTimeout="10000" doc:name="File" />
<file:file-to-string-transformer
doc:name="File to String" />
<splitter expression="#[xpath('//machineData')]" doc:name="Splitter"
enableCorrelation="ALWAYS" />
<mulexml:dom-to-xml-transformer
doc:name="DOM to XML" />
<file:outbound-endpoint transformer-refs="xslt"
path="C:\Temp\mule\out" responseTimeout="10000" doc:name="File"
outputPattern="#[message.outboundProperties.MULE_CORRELATION_SEQUENCE].xml" />
</flow>