apache camel - do we need to give xml prefix to child tags when it is already provided on the parent level -


this default camel-context provided in 1 of samples.

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans"        xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"        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">     <camel:camelcontext xmlns="http://camel.apache.org/schema/spring" id="samplecamelcontext">         <camel:route>       <camel:from uri="file:src/data?noop=true"/>       <camel:choice>         <camel:when>           <camel:xpath>/person/city = 'london'</camel:xpath>           <camel:log message="uk message"/>           <camel:to uri="file:target/messages/uk"/>         </camel:when>         <camel:otherwise>           <camel:log message="other message"/>           <camel:to uri="file:target/messages/others"/>         </camel:otherwise>       </camel:choice>     </camel:route>   </camel:camelcontext> </beans> 

now since default ns camel:camelcontext provided, need specify prefix in child tags too?

wouldn't work? (as alluded in https://stackoverflow.com/a/25789100/1873328)

<camel:camelcontext xmlns="http://camel.apache.org/schema/spring" id="samplecamelcontext">         <route>       <from uri="file:src/data?noop=true"/>       <choice>         <when>           <xpath>/person/city = 'london'</camel:xpath>           <log message="uk message"/>           <to uri="file:target/messages/uk"/>         </when>               </choice>     </route> </camel:camelcontext> 

maybe, not understand xml namespaces correctly. detail explanation of how namespaces work bonus appreciated.

the following 2 facts give answer:

  • child nodes use xmlns declaration closest parent node.
  • the prefix literal (e.g. camel) not matter - thing matters namespace refers to. if different prefixes refer same namespace, can used interchangingly, , not having prefix prefix (an empty one).

because xmlns declaration on camel:camelcontext refers same namespace xmlns:camel declaration, not matter if omit camel: these child nodes or not, in both cases listed against http://camel.apache.org/schema/spring namespace.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -