90.11. 在没有交换的情况下使用 XPathBuilder
				现在,您可以使用 org.apache.camel.language.xpath.XPathBuilder,而无需 交换。如果您要将其用作进行自定义 XPath 评估的帮助程序,请非常方便。
			
				它要求您传递 CamelContext,因为 XPathBuilder 中的许多移动部分需要访问 Camel Type Converter,因此需要 CamelContext。
			
例如,您可以执行以下操作:
boolean matches = XPathBuilder.xpath("/foo/bar/@xyz").matches(context, "<foo><bar xyz='cheese'/></foo>"));
boolean matches = XPathBuilder.xpath("/foo/bar/@xyz").matches(context, "<foo><bar xyz='cheese'/></foo>"));这将与给定的 predicate 匹配。
您还可以按照以下三个示例所示评估:
String name = XPathBuilder.xpath("foo/bar").evaluate(context, "<foo><bar>cheese</bar></foo>", String.class);
Integer number = XPathBuilder.xpath("foo/bar").evaluate(context, "<foo><bar>123</bar></foo>", Integer.class);
Boolean bool = XPathBuilder.xpath("foo/bar").evaluate(context, "<foo><bar>true</bar></foo>", Boolean.class);
String name = XPathBuilder.xpath("foo/bar").evaluate(context, "<foo><bar>cheese</bar></foo>", String.class);
Integer number = XPathBuilder.xpath("foo/bar").evaluate(context, "<foo><bar>123</bar></foo>", Integer.class);
Boolean bool = XPathBuilder.xpath("foo/bar").evaluate(context, "<foo><bar>true</bar></foo>", Boolean.class);
				使用 字符串 结果评估是一个常见要求,并使这一简单:
			
String name = XPathBuilder.xpath("foo/bar").evaluate(context, "<foo><bar>cheese</bar></foo>");
String name = XPathBuilder.xpath("foo/bar").evaluate(context, "<foo><bar>cheese</bar></foo>");