使用 xpath 进行过滤的 Camel

Camel in action filtering using xpath

您好,我正在学习 Camel(实际使用 Camel)。我在第 2 章(第 49 页)。过滤来自订单的消息

给出以下代码:

from("jms:xmlOrders").filter(xpath("/order[not(@test)]"))
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("Received XML order: "
+ exchange.getIn().getHeader("CamelFileName"));
}
});

Q1。消息中的所有内容都是订单元素吗?例如。订单名称=电机,订单金额=1 或订单名称=电机但金额=1?

Q2。 @ 是如何工作的?例如。考试?如果我想创建一个过滤器来过滤掉所有订单金额 > 1 的订单,我该怎么做?

此代码假定来自jms队列"xmlOrders"的消息是xml,或者可以转换为xml。

此路由然后在 xml 邮件上应用 xpath 过滤器。您可以在 Google 上找到很多关于 xpath 的教程:它是 xml 片段的查询语言。 /order[not(@test)] 表示 "an <order/> element without a test attribute"。例如,如果订单元素具有金额属性,您的查询可以是:"/order[@amount > 1]"

参见示例http://www.w3schools.com/xsl/xpath_intro.asp