如何从Mule foreach中的xml列表中提取值 [英] How to extract values from an xml list in Mule foreach

查看:147
本文介绍了如何从Mule foreach中的xml列表中提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下SOAP响应:-

I have a following SOAP response :-

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <retrieveAllDataResponse xmlns="http://services.test.com/schema/MainData/V1">
         <retrieveAllData>
            <Response>The Data retrieved from the Database</Response>
            <Id>1231</Id>
            <Name>test1</Name>
            <Age>560</Age>
            <Designation>Software Engineer</Designation>
         </retrieveAllData>
         <retrieveAllData>
            <Response>The Data retrieved from the Database</Response>
            <Id>165</Id>
            <Name>test2</Name>
            <Age>561</Age>
            <Designation>Senior Software Engineer</Designation>
         </retrieveAllData>
         <retrieveAllData>
            <Response>The Data retrieved from the Database</Response>
            <Id>134</Id>
            <Name>test3</Name>
            <Age>562</Age>
            <Designation>HR</Designation>
         </retrieveAllData>
</retrieveAllDataResponse>
   </soap:Body>
</soap:Envelope>

现在,我想从列表<retrieveAllData>中提取值,并将其放入 foreach 下的流变量中:-

Now I want to extract the values from the list <retrieveAllData> and put into flow variables under foreach :-

<foreach collection="#[xpath('//xmlns:retrieveDataResponse/xmlns:retrieveAllData')]" doc:name="For Each">
<set-variable doc:name="Variable" value="#[xpath('//xmlns:Id/text()').text]" variableName="id"/>
<logger level="INFO" message="#[flowVars['id']]" doc:name="Logger"/>
<set-variable doc:name="Variable" value="#[xpath('//xmlns:Name/text()').text]" variableName="name"/>
<logger level="INFO" message="#[flowVars['name']]" doc:name="Logger"/>
<set-variable doc:name="Variable" value="#[xpath('//xmlns:Age/text()').text]" variableName="age"/>
<logger level="INFO" message="#[flowVars['age']]" doc:name="Logger"/>
<set-variable doc:name="Variable" value="#[xpath('//xmlns:Designation/text()').text]" variableName="designation"/>

但是我没有将值添加到变量中..我正在获取以下内容:-

But I am not getting the values into the variables.. I am getting the following :-

 Splitter returned no results. If this is not expected, please check your split expression

请注意,我已经为命名空间..

Please note that I have already set XML namespace Manager for the namespace ..

请让我知道,还有什么更好的方法可以从列表中获取所有值并将其设置为流变量?

Please let me know is there any better way to get all the values from the list and set it into the flow variables ?

推荐答案

<flow name="xmlsplitter" doc:name="xmlsplitter">
    <file:inbound-endpoint path="C:/var/lib/data" doc:name="File"/>
    <file:file-to-string-transformer doc:name="File to String"/>    
    <logger level="INFO" message="#[payload:]" doc:name="Logger" /> 
    <foreach collection="#[xpath('//out:retrieveAllData')]" doc:name="For Each">

        <set-variable doc:name="Variable" value="#[xpath('out:Designation/text()').wholeText]" variableName="id"/>
        <logger level="INFO" message="#[flowVars['id']]" doc:name="Logger"/>

    </foreach>      
</flow>

这篇关于如何从Mule foreach中的xml列表中提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆