2017-02-27 73 views
0

我正在使用Enrich Mediator來豐富XML。Enrich調解器僅適用於WSO2 ESB中的第一個元素5

我的問題是,它總是適用於第一個元素,但我想將其應用於多個元素。我如何將它應用於XPATH選擇的所有元素?

我也試過下面的選項。但失敗。

//Response/ResponseDetails/SearchHotelPriceResponse/HotelDetails/Hotel[@HasExtraInfo="true"] 

富民配置:

<enrich> 
    <source type="inline"> 
     <ImageCode xmlns="">IMG10004</ImageCode> 
    </source> 
    <target action="child" xpath="//Response/ResponseDetails/SearchHotelPriceResponse/HotelDetails/Hotel[*]"/> 
</enrich> 

XML有效載荷:

<Response ResponseReference="REF_D_028_749-2801486459143247"> 
    <ResponseDetails Language="en"> 
     <SearchHotelPriceResponse> 
      <HotelDetails> 
       <Hotel HasExtraInfo="true" HasMap="true" HasPictures="true"> 
        <City Code="LON">London</City> 
        <Item Code="ALE1">ALEXANDRA</Item> 
        <StarRating>3</StarRating> 
        <HotelRooms> 
         <HotelRoom Code="SB" NumberOfRooms="1"/> 
        </HotelRooms> 
       </Hotel> 
       <Hotel HasExtraInfo="true" HasPictures="true"> 
        <City Code="LON">London</City> 
        <Item Code="ALO">Aloft London Excel</Item> 
        <StarRating>4</StarRating> 
        <HotelRooms> 
         <HotelRoom Code="SB" NumberOfRooms="1"/> 
        </HotelRooms> 
       </Hotel> 
       <Hotel HasExtraInfo="true" HasMap="true" HasPictures="true"> 
        <City Code="LON">London</City> 
        <Item Code="AMB3">Ambassadors Bloomsbury</Item> 
        <StarRating>4</StarRating> 
        <HotelRooms> 
         <HotelRoom Code="SB" NumberOfRooms="1"/> 
        </HotelRooms> 
       </Hotel> 
      </HotelDetails> 
     </SearchHotelPriceResponse> 
    </ResponseDetails> 
</Response> 
  • ESB 5.0.0

回答

5

使用「迭代」調解器,請檢查我的解決方案。

<?xml version="1.0" encoding="UTF-8"?> 
<proxy xmlns="http://ws.apache.org/ns/synapse" 
     name="EnrichProxy" 
     startOnLoad="true" 
     statistics="disable" 
     trace="disable" 
     transports="http,https"> 
    <target> 
     <inSequence> 
     <payloadFactory media-type="xml"> 
      <format> 
       <Response xmlns="" ResponseReference="REF_D_028_749-2801486459143247"> 
        <ResponseDetails Language="en"> 
        <SearchHotelPriceResponse> 
         <HotelDetails> 
          <Hotel HasExtraInfo="false" HasMap="true" HasPictures="true"> 
           <City Code="LON">London</City> 
           <Item Code="ALE1">ALEXANDRA</Item> 
           <StarRating>3</StarRating> 
           <HotelRooms> 
           <HotelRoom Code="SB" NumberOfRooms="1"/> 
           </HotelRooms> 
          </Hotel> 
          <Hotel HasExtraInfo="true" HasPictures="true"> 
           <City Code="LON">London</City> 
           <Item Code="ALO">Aloft London Excel</Item> 
           <StarRating>4</StarRating> 
           <HotelRooms> 
           <HotelRoom Code="SB" NumberOfRooms="1"/> 
           </HotelRooms> 
          </Hotel> 
          <Hotel HasExtraInfo="true" HasMap="true" HasPictures="true"> 
           <City Code="LON">London</City> 
           <Item Code="AMB3">Ambassadors Bloomsbury</Item> 
           <StarRating>4</StarRating> 
           <HotelRooms> 
           <HotelRoom Code="SB" NumberOfRooms="1"/> 
           </HotelRooms> 
          </Hotel> 
         </HotelDetails> 
        </SearchHotelPriceResponse> 
        </ResponseDetails> 
       </Response> 
      </format> 
      <args/> 
     </payloadFactory> 
     <property expression="$body" name="bodyBackup" type="OM"/> 
     <iterate expression="$body//Response/ResponseDetails/SearchHotelPriceResponse/HotelDetails/Hotel" 
        id="Hotels"> 
      <target> 
       <sequence> 
        <filter regex="true()" source="$body//Hotel/@HasExtraInfo"> 
        <then> 
         <enrich> 
          <source clone="true" type="inline"> 
           <ImageCode xmlns="">IMG10004</ImageCode> 
          </source> 
          <target action="child" xpath="$body//Hotel"/> 
         </enrich> 
        </then> 
        <else/> 
        </filter> 
        <loopback/> 
       </sequence> 
      </target> 
     </iterate> 
     </inSequence> 
     <outSequence> 
     <property name="HotelDetails" scope="default"> 
      <HotelDetails xmlns=""/> 
     </property> 
     <aggregate id="Hotels"> 
      <completeCondition> 
       <messageCount max="-1" min="-1"/> 
      </completeCondition> 
      <onComplete enclosingElementProperty="HotelDetails" expression="$body/*[1]"> 
       <enrich> 
        <source clone="true" xpath="$body/*[1]"/> 
        <target xpath="$ctx:bodyBackup//Response/ResponseDetails/SearchHotelPriceResponse/HotelDetails"/> 
       </enrich> 
       <enrich> 
        <source clone="true" xpath="$ctx:bodyBackup/*[1]"/> 
        <target type="body"/> 
       </enrich> 
       <send/> 
      </onComplete> 
     </aggregate> 
     </outSequence> 
    </target> 
    <description/> 
</proxy> 

對於該解決方案,這是結果

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Body> 
     <Response ResponseReference="REF_D_028_749-2801486459143247"> 
     <ResponseDetails Language="en"> 
      <SearchHotelPriceResponse> 
       <HotelDetails> 
        <Hotel HasExtraInfo="false" HasMap="true" HasPictures="true"> 
        <City Code="LON">London</City> 
        <Item Code="ALE1">ALEXANDRA</Item> 
        <StarRating>3</StarRating> 
        <HotelRooms> 
         <HotelRoom Code="SB" NumberOfRooms="1"/> 
        </HotelRooms> 
        </Hotel> 
        <Hotel HasExtraInfo="true" HasPictures="true"> 
        <City Code="LON">London</City> 
        <Item Code="ALO">Aloft London Excel</Item> 
        <StarRating>4</StarRating> 
        <HotelRooms> 
         <HotelRoom Code="SB" NumberOfRooms="1"/> 
        </HotelRooms> 
        <ImageCode>IMG10004</ImageCode> 
        </Hotel> 
        <Hotel HasExtraInfo="true" HasMap="true" HasPictures="true"> 
        <City Code="LON">London</City> 
        <Item Code="AMB3">Ambassadors Bloomsbury</Item> 
        <StarRating>4</StarRating> 
        <HotelRooms> 
         <HotelRoom Code="SB" NumberOfRooms="1"/> 
        </HotelRooms> 
        <ImageCode>IMG10004</ImageCode> 
        </Hotel> 
       </HotelDetails> 
      </SearchHotelPriceResponse> 
     </ResponseDetails> 
     </Response> 
    </soapenv:Body> 
</soapenv:Envelope> 
+0

沒錯! Thanx Ernesto。 – namalfernandolk

1

使用「foreach」調解器迭代「酒店」節點,並在它的序列中,可以使用富媒體(將調整單個節點)

+0

確定。我也會試試這個讓米歇爾。 Thanx – namalfernandolk