On Thu, Oct 18, 2012 at 10:46 AM, kmoens <kris_mo...@yahoo.com> wrote:
> Hi,
>
> had the same issue with a document having a default namespace defined, sth
> like
> <doc xmlns="urn:abc"><tag1><tag2>hello</tag2><tag3>world</tag3></tag1></doc>
>
> To get the value 'hello' from the above document, I tried in my bean
> public String getGreeting(@Xpath("doc/tag1/tag2/text()") String greeting) {
>  return greeting;
> }
> which returned an empty String.
>
> The solution is to 'mimic' if there was a prefix e.g. "p",  in this case the
> Xpath looks like:
> @Xpath(value="p:doc/p:tag1/p:tag2/text()", namespaces=
> @NamespacePrefix(prefix="p", uri="urn:abc"))
>
> which returned "hello".
>
> A bit cumbersome, but it worked ;)
>

Yeah unfortunately the XPath API for xpath expressions don't allow us
to hook into it, or some way "mimic" this default namespace for us. So
the only option is to assign a bogus namespace prefix. Or maybe have
luck with that /local() stuff.


> Hope this helps,
> Kris
>
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/XPath-namespaces-in-Spring-DSL-tp4556826p5721221.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cib...@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Reply via email to