You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Marcin Cylke <mc...@touk.pl> on 2011/09/12 14:28:53 UTC
Re: [ camel ] XML Namespace and Xpath injection
On 09/12/2011 02:21 PM, atouret.nospam@free.fr wrote:
> Hello,
> I'm trying to inject a value in bean trough an xpath injection as following :
>
>
> public void audit(@XPath("/Envelope/Body/getToken/username/text()") String id, @Body String body) {
> logger.info("Id :"+id );
> logger.info("Body = "+body);
> }
>
> Unfortunately, all the elements are fully qualified by a namespace.
You can pass namespaces to @XPath annotation, or create your own
annotation, with namespaces included:
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@LanguageAnnotation(language = "xpath", factory =
XpathExpressionAnnotationFactoryImproved.class)
public @interface StXpath {
String value();
// You can add the namespaces as the default value of the annotation
NamespacePrefix[] namespaces() default { @NamespacePrefix(prefix =
"st", uri = "http://example.pl/service/schemas") };
Class<?> resultType() default String.class;
}