Reputation: 223
I have below XML
<response>
<data-table filter="XXX" count="26">
<columns>
<column>sampm</column>
<column>sampn</column>
</columns>
<rows>
<row attr="535545">
<field>sampx</field>
<field>sampy</field>
</row>
<row attr="535548">
<field>samp1</field>
<field>samp2</field>
</row>
</rows>
</data-table>
</response>
From this response I have to loop over rows i.e; /response/data-table/rows/row
So here is my mule code snippet with for each
<http:request config-ref="HTTP_REQUEST" path="api/query" method="GET" doc:name="HTTP" followRedirects="true">
</http:request>
<object-to-string-transformer doc:name="Object to String"/>
<foreach collection="#[xpath3('//response/data-table/rows')]" doc:name="For Each">
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</foreach>
But I am getting a warning "The expression does not evaluate to a type that can be split: java.lang.String"
Is there any work around this problem
Upvotes: 0
Views: 800
Reputation: 33413
Specify the xpath3
return type to be a NODESET
:
<foreach
collection="#[xpath3('//query-response/data-table/rows', payload, 'NODESET')]"
This should be iterable.
Upvotes: 0
Reputation: 1401
Rows
would return you an object, try changing your expression to xpath3('//query-response/data-table/rows/row')
Upvotes: 1