2
这是在其中一个示例中提供的默认camel-context。我们是否需要为子标记提供xml前缀,当它已经在父级别上提供时
<?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>
现在既然提供了camel:camelContext
默认NS,我们需要在子标签也可以指定前缀?
这不工作? (如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>
也许,我不正确理解XML命名空间。值得赞赏的是,有关名称空间如何作为奖励的任何详细解释。
因此,如果我理解正确,因为' '有一个xmlns定义,所以没有任何前缀的子元素将继承这个名称空间。所以,我可以跳过' '本身的骆驼前缀,因为它已经定义了xmlns。 –
2015-04-01 16:39:29
是的,你可以。或者你可以放弃它,因为它可以提高可读性。 – GSerg 2015-04-01 16:44:36