NiFi EvaluateXPath处理器未返回所有结果。

huangapple go评论93阅读模式
英文:

NiFi EvaluateXPath Processor doesn't return all results

问题

  1. 我试图从示例XML中提取ID列表,并最好将它们写入流文件属性。
  2. XML:

<Data>
<Buckets>
<Data_Item>
<Data_Info ID="1234">
<Value>123</Value>
</Data_Info>
</Data_Item>
<Data_Item>
<Data_Info ID="5678">
<Value>456</Value>
</Data_Info>
</Data_Item>
<Data_Item>
<Data_Info ID="9999">
<Value>789</Value>
</Data_Info>
</Data_Item>
</Buckets>
</Data>

  1. XPath:
  2. `/Data/Buckets/Data_Item/Data_Info/@ID`
  3. 我在在线编辑器中测试了XPath,并返回了所有3ID,但当我将其输入到NiFi EvaluateXPath处理器中时,它要么抛出错误,要么只返回第一个ID
  4. 如果我将返回类型设置为`nodeset``auto-detect`,就会发生错误。
  5. 错误消息:`XPath evaluation on ... produced unexpected results [3]`
  6. 如果我将返回类型设置为`string`,我只会得到第一个ID1234)作为返回值。
  7. 如果我将目的地从`flowfile-attribute`更改为`flowfile-content`,也会出现相同的问题。
  8. 如何从XML中提取ID列表?
英文:

I'm trying to extract a list of IDs from an example XML, and preferably write them into a flowfile attribute.

XML:

  1. &lt;Data&gt;
  2. &lt;Buckets&gt;
  3. &lt;Data_Item&gt;
  4. &lt;Data_Info ID=&quot;1234&quot;&gt;
  5. &lt;Value&gt;123&lt;/Value&gt;
  6. &lt;/Data_Info&gt;
  7. &lt;/Data_Item&gt;
  8. &lt;Data_Item&gt;
  9. &lt;Data_Info ID=&quot;5678&quot;&gt;
  10. &lt;Value&gt;456&lt;/Value&gt;
  11. &lt;/Data_Info&gt;
  12. &lt;/Data_Item&gt;
  13. &lt;Data_Item&gt;
  14. &lt;Data_Info ID=&quot;9999&quot;&gt;
  15. &lt;Value&gt;789&lt;/Value&gt;
  16. &lt;/Data_Info&gt;
  17. &lt;/Data_Item&gt;
  18. &lt;/Buckets&gt;
  19. &lt;/Data&gt;

XPath:
/Data/Buckets/Data_Item/Data_Info/@ID

I tested the XPath with an online editor and it returned all 3 IDs, but when I enter it into the NiFi EvaluateXPath processor it either throws an error or only returns the first ID.

The error happens if I use nodeset or auto-detect for the return type.
Error Message: XPath evaluation on ... produced unexpected results [3]

If I use string as the return type I only get the first ID (1234) as a return value.

The same problems occur if I change the destination from flowfile-attribute to flowfile-content.

How can I extract a list of IDs from the XML?

答案1

得分: 1

1234,5678,9999

英文:

Use a this XPath Expression (using string-join):

  1. string-join(/Data/Buckets/Data_Item/Data_Info/@ID, &#39;,&#39;)

input

  1. &lt;Data&gt;
  2. &lt;Buckets&gt;
  3. &lt;Data_Item&gt;
  4. &lt;Data_Info ID=&quot;1234&quot;&gt;
  5. &lt;Value&gt;123&lt;/Value&gt;
  6. &lt;/Data_Info&gt;
  7. &lt;/Data_Item&gt;
  8. &lt;Data_Item&gt;
  9. &lt;Data_Info ID=&quot;5678&quot;&gt;
  10. &lt;Value&gt;456&lt;/Value&gt;
  11. &lt;/Data_Info&gt;
  12. &lt;/Data_Item&gt;
  13. &lt;Data_Item&gt;
  14. &lt;Data_Info ID=&quot;9999&quot;&gt;
  15. &lt;Value&gt;789&lt;/Value&gt;
  16. &lt;/Data_Info&gt;
  17. &lt;/Data_Item&gt;
  18. &lt;/Buckets&gt;
  19. &lt;/Data&gt;

output

  1. 1234,5678,9999

huangapple
  • 本文由 发表于 2023年6月29日 19:46:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76580732.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定