adding namespace to route for xpath in java DSL

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

adding namespace to route for xpath in java DSL

chiochuan
Hi,

i trying to use xpath to extract text and setting it to exchange property
```
            .setProperty(code, xpath("//code", String.class))
```
but seem that due to the xml body having namespace, xpath didnt manage
to extract the value.
i try to add namespace into the route, but don't seem to be work.

```

    public void configure() throws Exception {
        new Namespaces("com", "http://test.com/test");

        from("direct:...")
   }
```
understand that we can add the namespace in the spring DSL
```
<route xmlns="http://camel.apache.org/schema/spring"
       customId="true" xmlns:com="http://test.com/test" >

```
is that possible to do it on java DSL ?

Thanks and Regards,
Chio Chuan
Reply | Threaded
Open this post in threaded view
|

Re: adding namespace to route for xpath in java DSL

Claus Ibsen-2
Hi

Yes you can add namespace in Java DSL too, you need to add it on the
xpath and now in the top with a new constructor.

Look at the documentation.
https://camel.apache.org/components/latest/xpath-language.html


On Tue, Jan 7, 2020 at 1:35 AM Chio Chuan Ooi <[hidden email]> wrote:

>
> Hi,
>
> i trying to use xpath to extract text and setting it to exchange property
> ```
>             .setProperty(code, xpath("//code", String.class))
> ```
> but seem that due to the xml body having namespace, xpath didnt manage
> to extract the value.
> i try to add namespace into the route, but don't seem to be work.
>
> ```
>
>     public void configure() throws Exception {
>         new Namespaces("com", "http://test.com/test");
>
>         from("direct:...")
>    }
> ```
> understand that we can add the namespace in the spring DSL
> ```
> <route xmlns="http://camel.apache.org/schema/spring"
>        customId="true" xmlns:com="http://test.com/test" >
>
> ```
> is that possible to do it on java DSL ?
>
> Thanks and Regards,
> Chio Chuan



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|

Re: adding namespace to route for xpath in java DSL

chiochuan
Hi Claus,

Thank for the input, i manage to resolve it by adding namespace after the xpath.

     Namespaces test =  new Namespaces("com", "http://test.com/test");
     from("direct:...").setProperty(xpath("//com:param1/text()").namespaces(test))

Thanks and Regards,
Chio Chuan

On Tue, Jan 7, 2020 at 11:43 AM Claus Ibsen <[hidden email]> wrote:

>
> Hi
>
> Yes you can add namespace in Java DSL too, you need to add it on the
> xpath and now in the top with a new constructor.
>
> Look at the documentation.
> https://camel.apache.org/components/latest/xpath-language.html
>
>
> On Tue, Jan 7, 2020 at 1:35 AM Chio Chuan Ooi <[hidden email]> wrote:
> >
> > Hi,
> >
> > i trying to use xpath to extract text and setting it to exchange property
> > ```
> >             .setProperty(code, xpath("//code", String.class))
> > ```
> > but seem that due to the xml body having namespace, xpath didnt manage
> > to extract the value.
> > i try to add namespace into the route, but don't seem to be work.
> >
> > ```
> >
> >     public void configure() throws Exception {
> >         new Namespaces("com", "http://test.com/test");
> >
> >         from("direct:...")
> >    }
> > ```
> > understand that we can add the namespace in the spring DSL
> > ```
> > <route xmlns="http://camel.apache.org/schema/spring"
> >        customId="true" xmlns:com="http://test.com/test" >
> >
> > ```
> > is that possible to do it on java DSL ?
> >
> > Thanks and Regards,
> > Chio Chuan
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2