adding namespace to route for xpath in java DSL

2020-01-06 Thread Chio Chuan Ooi
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
```
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


Re: adding namespace to route for xpath in java DSL

2020-01-06 Thread Claus Ibsen
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  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
> ```
> 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


Re: adding namespace to route for xpath in java DSL

2020-01-07 Thread Chio Chuan Ooi
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  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  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
> > ```
> > 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