【问题标题】:Spring Integration Xpath Filter with Regex使用正则表达式的 Spring 集成 Xpath 过滤器
【发布时间】:2016-02-01 04:00:34
【问题描述】:

我正在使用 Xpath 过滤器来过滤掉一些传入事件。

这是我的示例输入 xml。我需要按 fieldC 的值进行过滤,允许 fieldC 值为 1、2、3、6 或 7 的事件。

<?xml version="1.0" encoding="UTF-8"?>
<add>
<doc>
<field name="fieldA">453.97</field>
<field name="fieldB">278.25</field>
<field name="fieldC">3</field>
<field name="fieldD">Agent</field>
<field name="fieldE">Mobile Site</field>
<field name="fieldF">Cancel</field>
<field name="fieldG">2015-09-14T13:17:21.000Z</field>
</doc>
</add>

Xpath 尝试过:
/add/doc/field[@name='fieldC']/text()
/add/doc/field[@name='fieldC']

<int:chain input-channel="channelIn" output-channel="channelOut">
 <int-xml:xpath-filter id="filterEvents" match-value="3" match-type="exact">
    <int-xml:xpath-expression expression="/add/doc/field[@name='fieldC']/text()" />
    </int-xml:xpath-filter>
 </int-xml:xpath-filter>
</int:chain>

按匹配类型“精确”过滤有效,但我无法使用正则表达式获得相同的效果。

正则表达式尝试:/^(1|2|3|6|7)$/

任何帮助将不胜感激。

【问题讨论】:

    标签: spring xpath filter spring-integration


    【解决方案1】:

    您的正则表达式语法错误;失去/s...

    match-value="^(1|2|3|6|7)$" match-type="regex"
    

    ...对我来说很好用。

    【讨论】:

    • 这里习惯上“接受”一个答案,如果它解决了您的问题 - 这将帮助其他人搜索问题/答案。单击左侧投票计数器下方的复选标记。
    猜你喜欢
    • 1970-01-01
    • 2022-01-27
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-20
    • 1970-01-01
    相关资源
    最近更新 更多