nifi-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy LoPresto <alopre...@apache.org>
Subject Re: EvaluateXPath to process xml data does not support nodeset
Date Fri, 13 Oct 2017 23:23:22 GMT
Putta,

Yes, EvaluateXPath can return multiple values given the proper expression [1]. You can only
store one result in the flowfile content however, so if your destination is “flowfile-content”,
only one expression can be evaluated. If you select “flowfile-attribute”, you can evaluate
multiple expressions and each will be stored in an attribute with the dynamic property’s
name.

However, if your result could be 257 XML nodes, I don’t recommend storing that in an attribute.
In your case, I would suggest having an EvaluateXPath processor to extract the column names
to an attribute, and then follow it with a ConvertRecord processor that uses a ScriptedRecordReader
to take advantage of simple Groovy XML parsing, and then CSVRecordSetWriter to write to CSV
format and specify a tab as the delimiter character. If you want, you can even take out the
EvaluateXPath and perform the column parsing in the scripted reader as well.

[1] https://stackoverflow.com/a/5095294/70465

Andy LoPresto
alopresto@apache.org
alopresto.apache@gmail.com
PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69

> On Oct 13, 2017, at 1:34 PM, Putta Challa <Putta.Challa@zaplabs.com> wrote:
> 
> Hi,
> 
> I am downloading data in xml format using GetHttp processor and trying to convert this
data into a tab separated value file.
> When I try to use EvaluateXPath processor to grab the header data (<COLUMNS> and
actual data <DATA> nodes from the xml file, have the following issues
> 
> 1)       With EvaluateXPath you can’t have 2 XPath’s defined. Is there a way to overcome
this limitation?
> 2)       even if I try to get just <DATA> nodes (there are multiple DATA nodes
in a given xml), I am getting the following exception.
> 
> 18:26:39 UTC ERROR 16fb46ea-015f-1000-0000-00007c5fd65b 172.31.192.18:8080
> EvaluateXPath[id=16fb46ea-015f-1000-0000-00007c5fd65b] Routing StandardFlowFileRecord[uuid=b941988f-f925-4ec2-a3e5-2830e47cbe8b,claim=StandardContentClaim
[resourceClaim=StandardResourceClaim[id=1507917338870-99, container=default, section=99],
offset=204551, length=204551],offset=0,name=listings.xml,size=204551] to 'failure' because
the XPath evaluated to 257 XML nodes
> 
> 
> Sample xml file contents:
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <COMPS ReplyCode="0" ReplyText="Operation Successful">
> <COUNT Records="258"/>
> <DELIMITER value="09"/>
> <COLUMNS>Column1Column2Column3Column4Column5 </COLUMNS>
> <DATA>value11 value12 value13 value14 value15</DATA>
> <DATA>value21 value22 value23 value24 value25</DATA>
> </COMPS>
> 
> Thank you,
> Putta Challa
> 
> 
> 
> This email may be confidential. If you are not the intended recipient, please notify
us immediately and delete this copy from your system.
> 


Mime
View raw message