Search code examples
apache-cameltalend

Getting a string result from XPath expression in Talend cSetHeader


I'm being stumped by something that should be trivial.

I've got an xml document, which is split using cSplitter using XPath which works fine, but then I want to set headers with values from the split document.

I've got a cSetHeader component with the Language set to XPath and the valid xpath. However, it returns the value as a NodeList object, when I need a string.

If I use an XPath expression that returns a string, it gives an exception as it can't convert to NodeList.

How, in Talend, do I configure the XPath expression to return a string. It seems ok if you're writing the camel directly, as there is a parameter, but I can't see how it is done in Talend.

Thanks!


Solution

  • I've figured it out...

    As it's a code generator, talend puts in the .xpath( ... ) whatever you type in the field - so if you want it to generate a string you put

    "/your/xpath/here", java.lang.String.class
    

    in the cSetHeader xpath field and the code generator puts your xpath string with the requested class in the right place!

    Easy! Now why didn't I think of that earlier...?