英文:
NiFi EvaluateXPath Processor doesn't return all results
问题
我试图从示例XML中提取ID列表,并最好将它们写入流文件属性。
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>
XPath:
`/Data/Buckets/Data_Item/Data_Info/@ID`
我在在线编辑器中测试了XPath,并返回了所有3个ID,但当我将其输入到NiFi EvaluateXPath处理器中时,它要么抛出错误,要么只返回第一个ID。
如果我将返回类型设置为`nodeset`或`auto-detect`,就会发生错误。
错误消息:`XPath evaluation on ... produced unexpected results [3]`
如果我将返回类型设置为`string`,我只会得到第一个ID(1234)作为返回值。
如果我将目的地从`flowfile-attribute`更改为`flowfile-content`,也会出现相同的问题。
如何从XML中提取ID列表?
英文:
I'm trying to extract a list of IDs from an example XML, and preferably write them into a flowfile attribute.
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>
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):
string-join(/Data/Buckets/Data_Item/Data_Info/@ID, ',')
input
<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>
output
1234,5678,9999
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论