Yes thanks Marco. I'd also figured this is the best workaround for the moment. It makes for ugly xpath expressions and fortunately we don't have much likliehood of namespace clashes, but it does work :-)
On 27 April 2012 14:16, Marco Westermann <marwesterm...@gmx.de> wrote: > Hi, > > I'm not sure if this is suitable for you in your use case, but in this cases > where namespaces doesn't work I don't refer to namespaces in my xpath like: > > .split().xpath("/*[local-name() = 'dxf']/*[local-name() = > 'organisationUnits']/*[local-name() = 'organisationUnit']") > > regards, Marco > > Am 24.04.2012 23:23, schrieb Bob Jolliffe: > >> On 24 April 2012 16:36, Claus Ibsen<claus.ib...@gmail.com> wrote: >>> >>> On Tue, Apr 24, 2012 at 5:11 PM, Bob Jolliffe<bobjolli...@gmail.com> >>> wrote: >>>> >>>> On 24 April 2012 15:22, Claus Ibsen<claus.ib...@gmail.com> wrote: >>>>> >>>>> Hi >>>>> >>>>> Thanks >>>>> >>>>> Just to be sure how do you refer to this external file? >>>>> >>>> I'm loading it with: >>>> >>>> FileInputStream is = new FileInputStream( file ); >>>> >>>> try >>>> { >>>> RoutesDefinition routes = camelContext.loadRoutesDefinition( is ); >>>> camelContext.addRouteDefinitions( routes.getRoutes() ); >>>> } >>>> catch ( Exception e ) >>>> { >>>> log.info( "Unable to load route: " + e.getMessage() ); >>>> return ERROR; >>>> } >>>> >>> Ah okay, I don't think namespaces is injected into the xpath/xquery >>> predicates/expression when you do it like that. >>> This is done using JAXB which loads the model from the XML. It would >>> require a bit more effort to discover the custom namespace >>> declarations. >>> >> Yes I am afraid you are right. Trying to think what workarounds there >> might be for this. Unfortunately we have no way of knowing in advance >> which namespaces we might be dealing with so I need a general >> mechanism for loading routes at runtime and being able to process >> various types of xml. I wonder how easy it might be to create my own >> xpath based splitter which handled the namespace issue? Maybe more >> trouble than it is worth. >> >> As a general suggestion, wouldn't it be a good idea generally for >> there to be a way of making the xpath expression aware of certain >> namespaces by picking up an xmlns declaration closer to where it is >> used. eg on the xpath element like<xpath xmlns:d="..">...</xapth>? >> >> I guess in the meantime I can make all my xpath expressions use >> local-name(). >> >> Regards >> Bob >> >>> >>>>> >>>>> >>>>> On Mon, Apr 23, 2012 at 6:54 PM, Bob Jolliffe<bobjolli...@gmail.com> >>>>> wrote: >>>>>> >>>>>> On 23 April 2012 17:29, Claus Ibsen<claus.ib...@gmail.com> wrote: >>>>>>> >>>>>>> Hi >>>>>>> >>>>>>> Do you declare the route in an external file, or how do you refer to >>>>>>> the xml file with that route? >>>>>>> Maybe you can post your full XML files. >>>>>> >>>>>> I have the route declared in an external file. The following is a >>>>>> complete listing of the file which illustrates the problem: >>>>>> >>>>>> <?xml version="1.0" encoding="UTF-8"?> >>>>>> <route xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >>>>>> xsi:schemaLocation="http://camel.apache.org/schema/spring >>>>>> camel-spring-2.9.1.xsd" >>>>>> xmlns="http://camel.apache.org/schema/spring" >>>>>> xmlns:d="http://dhis2.org/schema/dxf/2.0" >>>>>> id="dataUpdater"> >>>>>> >>>>>> <description>Import Metadata</description> >>>>>> <!-- every now and again ... --> >>>>>> <from >>>>>> uri="quartz://halfminute?trigger.repeatInterval=300000&trigger.repeatCount=10"/> >>>>>> <to >>>>>> uri="http://localhost/trunk/api/metaData.xml"/> >>>>>> <split> >>>>>> <xpath>/d:dxf/d:organisationUnits/d:orgainsationUnit</xpath> >>>>>> <log loggingLevel="INFO" message="Processed one orgunit" /> >>>>>> </split> >>>>>> </route> >>>>>> >>>>>> The error I get is: >>>>>> Failed delivery for (MessageId: >>>>>> ID-bobs-laptop-39546-1335131554800-0-25 on ExchangeId: >>>>>> ID-bobs-laptop-39546-1335131554800-0-24). Exhausted after delivery >>>>>> attempt: 1 caught: >>>>>> org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath: >>>>>> /d:dxf/d:organisationUnits/d:orgainsationUnit. Reason: >>>>>> javax.xml.xpath.XPathExpressionException (MarkerIgnoringBase.java >>>>>> [DefaultQuartzScheduler-camel-builtin_Worker-2]) >>>>>> >>>>>> Note that I have declared xmlns:d="http://dhis2.org/schema/dxf/2.0" on >>>>>> the route element. It seems this is not being picked up. >>>>>> >>>>>> Regards >>>>>> Bob >>>>>> >>>>>>> >>>>>>> On Mon, Apr 23, 2012 at 6:23 PM, Bob Jolliffe<bobjolli...@gmail.com> >>>>>>> wrote: >>>>>>>> >>>>>>>> I have an application where I load a camel context using spring and >>>>>>>> then add different spring dsl routes particular to individual site >>>>>>>> configurations. >>>>>>>> >>>>>>>> I am having trouble using an XPath splitter because of the issue >>>>>>>> with >>>>>>>> making namespaces visible to the XPath processor. >>>>>>>> >>>>>>>> I've seen from here >>>>>>>> >>>>>>>> (http://camel.465427.n5.nabble.com/fail-filter-XPATH-camel-td476424.html) >>>>>>>> that if the route is defined within a camel context, then you can >>>>>>>> make >>>>>>>> the namespace visible in the usual way, as a xmlns declaration in >>>>>>>> the >>>>>>>> root (context) element. >>>>>>>> >>>>>>>> But this doesn't seem to work if I am loading just a route into an >>>>>>>> existing context. >>>>>>>> >>>>>>>> <route xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >>>>>>>> xmlns="http://camel.apache.org/schema/spring" >>>>>>>> xmlns:d="http://dhis2.org/schema/dxf/2.0" >>>>>>>> id="dataUpdater"> >>>>>>>> >>>>>>>> <description>Import Metadata</description> >>>>>>>> <!-- every now and again ... --> >>>>>>>> <from >>>>>>>> uri="quartz://halfminute?trigger.repeatInterval=300000&trigger.repeatCount=10"/> >>>>>>>> <to >>>>>>>> uri="http://localhost/trunk/api/metaData.xml?"/> >>>>>>>> <split> >>>>>>>> <xpath>/d:/dxf2/d:organisationUnit</xpath> >>>>>>>> <to .... /> >>>>>>>> </split> >>>>>>>> >>>>>>>> Camel complains that the xpath expression is illegal. Has anyone >>>>>>>> come >>>>>>>> across (and maybe solved) this problem before? >>>>>>>> >>>>>>>> I've had a look at the tokenize xml approach, which seems nice (and >>>>>>>> efficient) but again it doesn't seem to handle namespaces. >>>>>>>> >>>>>>>> Any advice welcome. >>>>>>>> >>>>>>>> Regards >>>>>>>> Bob >>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> Claus Ibsen >>>>>>> ----------------- >>>>>>> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com >>>>>>> FuseSource >>>>>>> Email: cib...@fusesource.com >>>>>>> Web: http://fusesource.com >>>>>>> Twitter: davsclaus, fusenews >>>>>>> Blog: http://davsclaus.blogspot.com/ >>>>>>> Author of Camel in Action: http://www.manning.com/ibsen/ >>>>> >>>>> >>>>> >>>>> -- >>>>> Claus Ibsen >>>>> ----------------- >>>>> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com >>>>> FuseSource >>>>> Email: cib...@fusesource.com >>>>> Web: http://fusesource.com >>>>> Twitter: davsclaus, fusenews >>>>> Blog: http://davsclaus.blogspot.com/ >>>>> Author of Camel in Action: http://www.manning.com/ibsen/ >>> >>> >>> >>> -- >>> Claus Ibsen >>> ----------------- >>> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com >>> FuseSource >>> Email: cib...@fusesource.com >>> Web: http://fusesource.com >>> Twitter: davsclaus, fusenews >>> Blog: http://davsclaus.blogspot.com/ >>> Author of Camel in Action: http://www.manning.com/ibsen/ > >