Hi ,

I know you are using JAVA DSL, but I have got what you want using the XML
DSL, maybe someone can put you right from my example.

The two points that are probably important are
1) Giving the namespace a prefix -----
xmlns:x="urn:iso:std:iso:20022:tech:xsd:DRAFT15auth.016.001.01"
2) In the second split using the prefix for both New and the Tx tags

I just ran from the consol with your xml file


<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<beans xmlns="http://www.springframework.org/schema/beans";
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xmlns:x="urn:iso:std:iso:20022:tech:xsd:DRAFT15auth.016.001.01"
       xmlns:camel="http://camel.apache.org/schema/spring";
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
         http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
         http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd";>

 <camelContext xmlns="http://camel.apache.org/schema/spring"; trace="false">

    <route id="Test XML splitter" streamCache="true">
<from
uri="file://src/data/?fileName=splitterxmltest.xml&amp;noop=true&amp;delay=500"/>

<split streaming="true">
<xtokenize>//x:Tx</xtokenize>
<log message="Body in First tokenize split = ${body}"/>
<!-- get some elementvalue and output to log-->
<setHeader headerName="TxId">
<xpath>//x:TxId/text()</xpath>
</setHeader>
<log message="TxId = ${header.TxId} ***************"/>
<!-- Do the second split  -->
<to uri="direct:secondSplit"/>

            </split>
    </route>


<!--
************************************************************************************************
-->
<!-- Second Split Route
                         * -->
<!--
************************************************************************************************
-->
<route id="second level split">
<from uri="direct:secondSplit"/>

<split streaming="true">
<xtokenize>//x:New/x:Tx</xtokenize>
               <!-- output body to the log -->
<log message="Body in second tokenize split = ${body}"/>
</split>


      </route>


</camelContext>
</beans>

On Thu, Jun 18, 2020 at 2:51 PM Mikael Andersson Wigander <
mikael.grevs...@gmail.com> wrote:

> My latest tests reveal that when using local-name() I get everything with
> the tag <Tx> (of course).
>
> But I cannot see how to manipulate the xpath expression.
>
> final XPathBuilder xPathBuilder =
> XPathBuilder.xpath("//*[local-name()='Tx']");
>
> When trying out it in http://xpather.com/ using
>
> //FinInstrmRptgTxRpt/*[local-name()='Tx']
>
> I get what I want but not in my code,. it returns nothing
>
> final XPathBuilder xPathBuilder =
> XPathBuilder.xpath("//FinInstrmRptgTxRpt/*[local-name()='Tx']");
>
>
>
> > On 18 Jun 2020, at 10:39, Claus Ibsen <claus.ib...@gmail.com> wrote:
> >
> > On Thu, Jun 18, 2020 at 10:15 AM Mikael Andersson Wigander
> > <mikael.grevs...@gmail.com <mailto:mikael.grevs...@gmail.com>> wrote:
> >>
> >> OK, interesting.
> >>
> >> I tested the Xpath using a online tester and there it works without
> using any namespace.
> >>
> >> Is it possible using XPath without namespaces or are there any xpath
> arguments that can be used?
> >>
> >
> > No really not, java xpath requires the namespace, but there is some
> > "trick" with local-ns() or some weird syntax I kinda think may be
> > possible.
> >
> >> M
> >>
> >>> On 18 Jun 2020, at 09:53, Alex Dettinger <aldettin...@gmail.com>
> wrote:
> >>>
> >>> Hi Mikael,
> >>>
> >>> I've noticed that the incoming xml file is involving 2 xml namespaces
> >>> while the query looks not.
> >>> Precising namespaces in the xpath query may help to move further,
> something
> >>> like:
> >>>
> https://github.com/apache/camel/blob/master/core/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTest.java#L241
> >>>
> >>> hth,
> >>> Alex
> >>>
> >>> On Thu, Jun 18, 2020 at 9:36 AM Mikael Andersson Wigander <
> >>> mikael.grevs...@gmail.com> wrote:
> >>>
> >>>> Hi
> >>>>
> >>>> My problem is that I can’t extract some XML using xpath in Camel 3.3.0
> >>>>
> >>>> My incoming XML is complicated where my target tag <Tx></Tx> also has
> a
> >>>> tag further down the tree as <Tx></Tx>.
> >>>>
> >>>> I have created a demo project on Github for share if someone could
> help
> >>>> me. https://github.com/hakuseki/xpath
> >>>>
> >>>> I have tested with a more “friendly” XML and both tests manage to
> retrieve
> >>>> the XML segment I want.
> >>>>
> >>>> This type of XML we get from client is based on a EU/ESMA standard.
> >>>>
> >>>> Pls advice
> >>>>
> >>>> Thx
> >>>>
> >>>> /M
> >>>>
> >>>>
> >>
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > http://davsclaus.com <http://davsclaus.com/> @davsclaus
> > Camel in Action 2: https://www.manning.com/ibsen2 <
> https://www.manning.com/ibsen2>
>


-- 
Bob Anderson
+27 (0) 82 389 0335
[image: View my profile on LinkedIn]
<http://ng.linkedin.com/pub/bob-anderson/2/25/9b5>

Reply via email to