2015-03-19 71 views
2

我需要接收一个传入的XML消息,其中包含重复元素,并将它们拆分为单独的消息以供继续处理。然后我需要重新组合结果并通过HTTP进行响应。Mule XPath Splitter不能工作在第一个元素之外

我在第一步使用了Splitter节点和XPath。但是,它只访问XML中的第一个元素,并且不会将XML保留到下一个阶段。我试过the example from the documentation,但它有相同的输出。

我在Anypoint Studio中运行Mule 3.6.1 CE。

NB处理元素的顺序将很重要,因此我不只是想做一个分散聚集。

这里是我的示例XML: -

<?xml version="1.0" encoding="UTF-8"?> 
<itm:ItemList 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:itm="http://schemas.goochjs.org/item-v1" 
     xsi:schemaLocation="http://schemas.goochjs.org/item-v1 item-v1.xsd"> 

    <itm:Item sequence="1" action="create"> 
     <itm:Thing type="something"> 
      <itm:Description>Something</itm:Description> 
     </itm:Thing> 

     <itm:Thing type="anything"> 
      <itm:Description>Something else</itm:Description> 
     </itm:Thing> 
    </itm:Item> 

    <itm:Item sequence="2" action="update"> 
     <itm:Thing type="anything"> 
      <itm:Description>A wotsit</itm:Description> 
     </itm:Thing> 
    </itm:Item> 

    <itm:Item sequence="2" action="create"> 
     <itm:Thing type="something"> 
      <itm:Description>A doohinky</itm:Description> 
     </itm:Thing> 
    </itm:Item> 

    <itm:Item sequence="3" action="delete"> 
     <itm:Thing type="something"> 
      <itm:Description>A different doohinky</itm:Description> 
     </itm:Thing> 
    </itm:Item> 
</itm:ItemList> 

这里是我的代码: -

<?xml version="1.0" encoding="UTF-8"?> 

<mule 
    xmlns:http="http://www.mulesoft.org/schema/mule/http" 
    xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" 
    xmlns:jms="http://www.mulesoft.org/schema/mule/jms" 
    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" version="CE-3.6.1" 
    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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
    http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd"> 
    <http:listener-config name="splitter-endpoint" host="0.0.0.0" port="8081" basePath="/splitter" doc:name="HTTP Listener Configuration"/> 
    <mulexml:namespace-manager includeConfigNamespaces="true"> 
     <mulexml:namespace prefix="itm" uri="http://schemas.goochjs.org/item-v1"/> 
    </mulexml:namespace-manager> 

    <flow name="mule-splitter-aggregatorFlow"> 
     <http:listener config-ref="splitter-endpoint" path="/" allowedMethods="post" doc:name="HTTP"/> 
     <splitter expression="#[xpath3('/itm:ItemList/itm:Item')]" doc:name="Splitter"/> 
     <logger message="#[message.payload]" level="INFO" doc:name="Logger"/> 
    </flow> 
</mule> 

而且这是在日志中输出: -

INFO 2015-03-19 10:48:17,440 [[mule-splitter-aggregator].splitter-endpoint.worker.01] org.mule.routing.ExpressionSplitter: The expression does not evaluate to a type that can be split: java.lang.String 
INFO 2015-03-19 10:48:17,441 [[mule-splitter-aggregator].splitter-endpoint.worker.01] org.mule.api.processor.LoggerMessageProcessor: 

      Something 



      Something else 

我在想什么?我曾尝试在分割之前添加各种不同的变形器(例如Object to XML,建议为here),但无济于事。

回答

4

尝试迫使XPath表达式返回NODESET:

<splitter expression="#[xpath3('/itm:ItemList/itm:Item', payload, 'NODESET')]" 
     doc:name="Splitter" /> 
+2

谢谢 - 我不得不也加入* DOM为XML *节点之后,但随后的拆分工作,因为它应该。我很快得出结论,骡的文档有点波浪 - 方便... ;-) – 2015-03-19 14:28:40

+0

我想指出,这也让我恼火,直到我添加了“DOM to XML”节点。它确实应该放在文档的某处。 – Tony 2016-04-13 22:28:56