Support Questions

Find answers, ask questions, and share your expertise

How do you declare a namespace for proper XPath use within EvaluateXPath

I have made some progress understanding and using EvaluateXPath.

I've been able, for example, to generate a flow file with the content

<?xml version="1.0" encoding="UTF-8"?><bookstore>  <book>    <title lang="en">Harry Potter</title>    <author>J K. Rowling</author>    <year>2005</year>    <price>29.99</price>  </book></bookstore>

and match this using the following (notice //year as the XPath)


However if I have a namespace in the XML


, then I have a problem (notice //ns8:textNOTAM as the XPath)



Oh No!! It looks like there has been an issue outstanding for over 2 years...

Is there no way for me to use EvaluateXPath on XML that contains namespaces?

Omg.. that worked!!

The XPath I had to use (within the EvaluateXPath processor configuration) was as follows:


This is stuff that should live in a NIFI user manual someplace.

Also an interesting stackoverflow link

it seems that maybe there is a workaround that i can use with evaluatexpath it might look something like the following


I've found several interesting stack overflow articles.. including the following:

I should be able to match the book in the following with a simple //bk:book

<bk:bookstore xmlns:bk="urn:xmlns:25hoursaday-com:bookstore">
    <bk:title>Lord of the Rings</bk:title> 
    <bk:author>J.R.R. Tolkien</bk:author>
    <inv:inventory status="in-stock" isbn="0345340426" 
        xmlns:inv="urn:xmlns:25hoursaday-com:inventory-tracking" />

Somehow NIFI needs to let me register the namespace.

I've also tried out online xpath formatters, and they have allowed me to simply add the namespace to the xpath as follows

matches //bk:book


New Contributor

Instead of using local-name, you can also do this:


This has a wildcard for the namespace prefix, and the element name in the place where you would expect it.

This tends to be more readable for longer XPaths like


Thanks @Nico Verwer. I'll give that a shot, and will be sure to accept your response as an answer, once I verify.

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.