<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: NiFi: Extract atrribute value from XML using EvaluateXPath in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Extract-atrribute-value-from-XML-using-EvaluateXPath/m-p/394154#M248674</link>
    <description>&lt;P&gt;Thanks to the second OP for identifying the root cause in the &lt;A href="https://issues.apache.org/jira/browse/NIFI-5567" target="_self"&gt;NiFi Jira&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;For people researching this today, the cause was the implicit/default Namespace specified in the root node (the 'xmlns' referenced in that element but &lt;STRONG&gt;without&lt;/STRONG&gt; a suffix).&amp;nbsp; In the case of the second poster, their XML started with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;data xmlns="http://www.media-saturn.com/msx" xmlns: ...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The `/data/item//uniqueID` he was searching for belongs to, more accurately, the "&lt;STRONG&gt;&lt;A href="http://www.media-saturn.com/msx" target="_blank" rel="noopener"&gt;http://www.media-saturn.com/msx&lt;/A&gt;&lt;/STRONG&gt;" namespace, meaning that - &lt;EM&gt;he was supposed to&lt;/EM&gt; - specify that namespace as part of his XPath expression.&lt;/P&gt;&lt;P&gt;The reason that searching for the pathless "//@uniqueType" worked, was because that search searches &lt;STRONG&gt;all namespaces&lt;/STRONG&gt; for that XPath expression!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using NiFi 2.0.0 M4 today and I'm pleased to report that it appears to support the XPath 3.0/3.1 notation where &lt;EM&gt;the Namespace can be specified inline with the query&lt;/EM&gt;.&amp;nbsp; It's not particularly elegant - but &lt;STRONG&gt;it works&lt;/STRONG&gt;.&amp;nbsp; You prefix the Namespace with the capital Letter 'Q' and wrap it in curly brackets; namely:&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;Q{&lt;A href="http://www.media-saturn.com/msx" target="_blank" rel="noopener"&gt;http://www.media-saturn.com/msx&lt;/A&gt;}&lt;/STRONG&gt;&lt;EM&gt;&amp;lt;single-level selector&amp;gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;To implement his expression, "&lt;STRONG&gt;/data/item//uniqueID[UniqueType='ProdID']/text()&lt;/STRONG&gt;" which currently returns an Empty String set for Key '&lt;STRONG&gt;ProdID4&lt;/STRONG&gt;', you would use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;/Q{http://www.media-saturn.com/msx}data/Q{http://www.media-saturn.com/msx}item//uniqueID[UniqueType='ProdID']/text()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have a suspicion that the second Namespace reference (to 'item' in this case) is not required, since once you've selected/are navigating down the 'data' path of the correct Namespace, you're not likely to jump to another Namespace?&amp;nbsp; My research indicates that Attributes do not seem to accept Namespace referencing - but again, once you've successfully selected your path I suspect it becomes a moot point.&lt;/P&gt;&lt;P&gt;Aside,&lt;BR /&gt;[1] it would be nice if the NiFi documentation specified the version of the XPath implemented within the Processor.&lt;BR /&gt;[2] Even better if there were a drop down within the Processor that allowed a developer to select the version of XPath expression desired.&lt;/P&gt;</description>
    <pubDate>Sun, 29 Sep 2024 02:04:37 GMT</pubDate>
    <dc:creator>HearMonster</dc:creator>
    <dc:date>2024-09-29T02:04:37Z</dc:date>
  </channel>
</rss>

