camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Djeeaie ." <djee....@gmail.com>
Subject Inconsistent return from XpathBuilder.evaluate()
Date Tue, 11 Aug 2015 12:49:49 GMT
Hello,

while trying to parse xml outside a camel route using xpath (as
described here :
http://camel.apache.org/xpath.html#XPath-UsingXPathBuilderwithoutanExchange),
I met an issue while trying to set the type of the return.
It seems that if you use the setResultType(Class<T> resultType) before
the evaluate, it will use the type correclty but will only return the
first element. But if you use evaluate(CamelContext context, Object
body, Class<T> type), it will return all elements at once.

I included a short snippet illustrating the issue I encountered :

    CamelContext cc = new DefaultCamelContext();
    String xml = "<xml><a>1</a><a>2</a></xml>";
    XPathBuilder xpb = new XPathBuilder("/xml/a/text()");
    System.out.println(xpb.evaluate(cc, xml, String.class));
    xpb.setResultType(String.class);
    System.out.println(xpb.evaluate(cc, xml));

String.class can be replaced by List.class and will return a List with
2 elements in the first case, and a null in the second.

I encountered this behaviour in Camel 2.15.2 and wanted to know if
it's a normal behaviour and I missed a way to set the result type
outside of the evaluate method and still get all nodes in one call.

Mime
View raw message