I've analyzed a generic implementation using DOM to copy the namespaces but
due to lack of time to check performance impact I ended up with a faster
solution specific to my route. As I was using JAXB to unmarshal the XML in
a later moment I decided to unmarshal it earlier and split using simple
language.

The route became something like:
    <route>
        <from uri="..."/>
        <unmarshal ref="jaxb-ctxt"/>
        <split>
            <simple>${body.collection.items}</simple>
            <to uri="log:split-object"/>
        </split>
    </route>

The DOM solution did not seem hard to implement but it could impact
performance as any parent node may define (re-define) namespaces which
would be copied to 'n' nodes in the NodeList.

att.
*Henrique Viecili*


On Sun, Nov 11, 2012 at 8:39 AM, Claus Ibsen <[email protected]> wrote:

> On Tue, Nov 6, 2012 at 1:04 PM, Henrique Viecili <[email protected]>
> wrote:
> > Thanks Claus, I will try this solution...
> >
> > As a second thought, could this behaviour be added as an enhancement to
> the
> > Type Converters or maybe camel-xpath itself?
> >
>
> Did you find a solution for your problem?
>
> The type converters wont really be able to be configured to
> enable/disalbe this. It would be better as an option to the xpath
> expression.
>
>
>
> >
> >
> > On Tue, Nov 6, 2012 at 5:17 AM, Claus Ibsen <[email protected]>
> wrote:
> >
> >> Hi
> >>
> >> You are under the mercy of XPath and what XPathExpression can do.
> >> As it returns a NodeList which has Node elements, you may be able to
> >> go from Node -> Document (or whatever the parent type is), and then
> >> grab any namespaces. You would then need to use the DOM API from the
> >> JDK for that.
> >>
> >> And do this before you do the <convertBodyTo type="String"/>
> >>
> >>
> >> On Mon, Nov 5, 2012 at 9:44 PM, Henrique Viecili <[email protected]>
> >> wrote:
> >> > Is there a way to tell the splitter-xpath to copy all parent
> namespaces
> >> to
> >> > the splitted element?
> >> >
> >> > This is what I am trying to do:
> >> >
> >> > I am trying to split an XML message with XPath, this message has a
> schema
> >> > defining an element containing a sequence of xsi:anySimpleType.
> Creating
> >> > such message gives me something like:
> >> >
> >> > <alpha:root xmlns:alpha="http://test.com/Alpha"; xmlns:beta="
> >> > http://test.com/Beta";>
> >> >     <alpha:collection>
> >> >         <alpha:item xsi:type="beta:BetaItem" xmlns:xsi="
> >> > http://www.w3.org/2001/XMLSchema-instance";>
> >> >             <beta:name>Foo</beta:name>
> >> >         </alpha:item>
> >> >         <alpha:item xsi:type="beta:BetaItem" xmlns:xsi="
> >> > http://www.w3.org/2001/XMLSchema-instance";>
> >> >             <beta:name>Bar</beta:name>
> >> >         </alpha:item>
> >> >     </alpha:collection>
> >> > </alpha:root>
> >> >
> >> >
> >> > my camel route is:
> >> >
> >> > <camelContext xmlns:alpha="http://test.com/Alpha"; xmlns:beta="
> >> > http://test.com/Beta"; >
> >> >     <route>
> >> >         <from uri="..."/>
> >> >         <split>
> >> >             <xpath>//alpha:item</xpath>
> >> >             <convertBodyTo type="java.lang.String"/>
> >> >             <to uri="log:output-missing-beta-namespace"/>
> >> >         </split>
> >> >     </route>
> >> > </camelContext>
> >> >
> >> >
> >> > feeding this route with the previous XML gives me 2 pieces of invalid
> XML
> >> > messages without the 'beta' namespace defined in the root element:
> >> >
> >> > <alpha:item xmlns:alpha="http://test.com/Alpha";
> xsi:type="beta:BetaItem"
> >> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
> >> >     <beta:name>Foo</beta:name>
> >> > </alpha:item>
> >> >
> >> > So, Is there a way to tell the splitter-xpath to copy the 'beta'
> >> namespace
> >> > from 'root' declaration into the splitted 'alpha:item' element?
> >> >
> >> >
> >> > Thanks
> >> > *Henrique Viecili*
> >>
> >>
> >>
> >> --
> >> Claus Ibsen
> >> -----------------
> >> Red Hat, Inc.
> >> FuseSource is now part of Red Hat
> >> Email: [email protected]
> >> Web: http://fusesource.com
> >> Twitter: davsclaus
> >> Blog: http://davsclaus.com
> >> Author of Camel in Action: http://www.manning.com/ibsen
> >>
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: [email protected]
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Reply via email to