Thanks James.
Not sure if I'm ready for XQuery yet. I think I was hoping for a one-line
solution ;)
But I now managed to do it with a custom expression:
context.addRoutes(
new RouteBuilder() {
@Override
public void configure() {
from("direct:cats")
.splitter(new Expression<Exchange>() {
public Object evaluate(Exchange exchange) {
log.debug("evaluate()");
HashMap<String,String> snippets = new
HashMap<String,String>();
org.dom4j.Document xmlDoc =
(new
DOMReader()).read(exchange.getIn().getBody(
org.w3c.dom.Document.class));
Iterator<Node> it =
xmlDoc.selectNodes("cats/cat").iterator();
while (it.hasNext()) {
Node child = it.next();
String key =
child.valueOf("colour/@id");
if (snippets.containsKey(key)) {
snippets.put(key,
snippets.get(key)+child.asXML());
} else {
snippets.put(key, child.asXML());
}
}
return snippets.values();
}
})
.setBody(el("<cats>${in.body}</cats>"))
.to("mock:result");
}
}
);
James.Strachan wrote:
>
> I guess this is a great use case for XQuery, where you can use the
> kinda SQL-ish nature to iterate through all values of the colour id,
> then for each of them create a kinda nested document; then split that
> into pieces. (You could use XSLT as well).
>
> So transform into something like
>
> <colours>
> <colour id="1"> <cat/> <cat/> </colour>
>
> Then split on /colours/colour
>
--
View this message in context:
http://www.nabble.com/Splitter-advice-tf4696876s22882.html#a13428590
Sent from the Camel - Users mailing list archive at Nabble.com.