How to extract values from an xml list in Mule foreach

给你一囗甜甜゛ 提交于 2019-12-02 12:30:38
t.subramanian80

<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>

I believe you have a problem with the namespaces, xmlns is used to indicate the root namespace of an element and its children, however you are using an xpath using it as prefix, i.e: //xmlns:retrieveDataResponse/xmlns:retrieveAllData', which is wrong. Try defining namespace myNameSpace the URI http://services.test.com/schema/MainData/V1 and then use it in the xpath fuction: //myNameSpace:retrieveDataResponse/myNameSpace:retrieveAllData'.

Also if you are using namespaces you will likely have problems with xpath functions as per MULE-6508, try also the wordaround of disabling the inclusions of the mule namespaces.

Finally if this is for an ongoing development, please give it a try to the very-soon-to-be-released Mule 3.6 that includes a much improved support for XML as per wiki and jira.

So the final working solution is using the following XPATH and is working for me :- #[xpath('out:Designation/text()').wholeText]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!