camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rbkumar88 <rbkuma...@gmail.com>
Subject camel xpath nodelist to List of String
Date Tue, 05 Apr 2016 23:06:06 GMT
Hi,

Is there any quick way to convert xpath nodelist to a list of Strings.
E.g.,
<Root>
....
<ValueList>
    <Value>123</Value>
    <Value>234</Value>
......
</ValueList>
</Root>


Currently for converting the above result into a comma separated string like
(123,234 etc...), am using the pretty complex code

<setProperty propertyName="ValueList">
						<xpath>//Root/...../ValueList</xpath>
					</setProperty>

Optional obj =Optional.of(exchange.getProperty("ValueList"));

if(obj.isPresent()
					&& obj.get() instanceof
com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList
					&&
((com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList)obj.get()).getLength()>0){
				com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList nodeList =
						(com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList)obj.get();

					String valueList=IntStream.range(0,
nodeList.item(0).getChildNodes().getLength()).sequential()
				.mapToObj(i ->
nodeList.item(0).getChildNodes().item(i).getTextContent())
				.filter(name -> name!=null && name.trim().length()>2)
				.collect(Collectors.joining(","));
}
			

Regards
Bharath



--
View this message in context: http://camel.465427.n5.nabble.com/camel-xpath-nodelist-to-List-of-String-tp5780530.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message