NIFI:如何在nifi处理器中使用变量节点名来获取节点值

时间:2017-10-16 18:15:02

标签: java groovy apache-nifi

我有如下所示的xml数据,我希望按名称获取localAttribtes标签' rs'在我的EvaluateXpath处理器中,我在我的EvaluateXpath处理器//localAttributes/*[@name='rs']/name()中尝试了这个表达式,但我没有得到" rs"标签值: enter image description here

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<service>
<localAttributes name="rs">    
<start>2017-09-07</start>    
<startDate>2017-02-02</startDate>    
<endDate>2017-03-02</endDate>    
<runAs>true</runAs>    
<patch>this is  patch</patch>    
<makeVersion>1</makeVersion>
</localAttributes>
<localAttributes name="ns">    
<start>2017-09-07</start>    
<startDate>2017-02-02</startDate>    
<endDate>2017-03-02</endDate>    
<runAs>true</runAs>    
<patch>this is  patch</patch>    
<makeVersion>1</makeVersion>
</localAttributes>
</service>

1 个答案:

答案 0 :(得分:1)

对于这种情况,正确的xpath是:

//localAttributes[@name='rs']/name()

但评估name()非常奇怪,因为它会返回标记名称并且您事先知道标记名称 - localAttributes

如果您希望获得patch的{​​{1}}标记值localAttributes,其属性@name等于'rs'

//localAttributes[@name='rs']/patch