【发布时间】:2018-05-11 15:55:00
【问题描述】:
尝试在 NiFi 中解析下面的 xml,并希望解析出所有 id 并为每个 id 进行多个 Web 服务调用。
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
</soap:Header>
<soap:Body>
<store-Ids>
<Id>69E32281-0484</Id>
<Id>3002AFCD-B494</Id>
<Id>2C9E17AC-9D97</Id>
<Id>98E8EB10-7D6A</Id>
<Id>F8D5F93C-1455</Id>
<Id>98655C3F-B58C</Id>
<Id>8AE4FD0A-6000</Id>
<Id>E56FE4CA-0D83</Id>
</store-Ids>
</soap:Body>
</soap:Envelope>
有没有办法解析出Id标签中的所有id?可以作为数组(69E32281-0484、3002AFCD-B494......)或作为字符串(69E32281-0484 3002AFCD-B4942C9E17AC-9D97............ ....) 使用 Evaluate-XPath 或 Evaluate-xQuery 处理器?
//*[local-name()='Id']/text() -------- This gives me only the 1st id. and
//*[local-name()='Id'][2]/text() ------- This gives the 2nd id and so on....
//Id -------------------------------- This returns "Empty string set"
因为 Id 的数量将是动态的。无法硬编码像 [0]、[1]、[2]........ 这样的计数器值来获取每个 id 的值。
PS:在 NiFi 中还有很多其他方法可以做到这一点。但想知道是否有办法使用 EvaluateXpath 处理器读取 XML 并将所有 id 标签值作为数组或文本获取。
相关链接
【问题讨论】:
标签: xml xml-parsing apache-nifi hortonworks-dataflow