Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Using EvaluateXpath prossessor in nifi

avatar
Contributor

I have response like this and i want to extract ErrorCode value from response flowfile anc check if it is equal to -7 and if it is, I will have to log this. I tried this in EvaluateXpath processor:/Error/ErrorCode/text() but it doesn't work for me after passing EvaluateXpath processor flowfile attribute errorCode which i have added with above mentioned command(/Error/ErrorCode/text()) seems to be emty string set

  1. what should i change to get value of ErrorCode in errorcode atribute?
<Result xmlns="olineservice" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ResponseStatus>false</ResponseStatus>
<Error>
<ErrorCode>-7</ErrorCode>
<ErrorDescription>data  wasn't  found</ErrorDescription>
</Error>
</Result>
1 ACCEPTED SOLUTION

avatar

From my answer to this question on Stack Overflow:

To extract the desired value, use the XPath expression //ErrorCode. This will return a String value -7. By selecting Destination flowfile-attribute, you can keep the flowfile content constant and put this new value in a flowfile attribute (i.e. named attribute).

You can chain the matched relationship to an UpdateAttribute processor which has the expression ${attribute:toNumber()} to convert it to a numerical representation, i.e. ${attribute:toNumber():plus(10)} would return 3.

View solution in original post

1 REPLY 1

avatar

From my answer to this question on Stack Overflow:

To extract the desired value, use the XPath expression //ErrorCode. This will return a String value -7. By selecting Destination flowfile-attribute, you can keep the flowfile content constant and put this new value in a flowfile attribute (i.e. named attribute).

You can chain the matched relationship to an UpdateAttribute processor which has the expression ${attribute:toNumber()} to convert it to a numerical representation, i.e. ${attribute:toNumber():plus(10)} would return 3.