2015-03-19 68 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