当父级已经提供xml前缀时,我们是否需要为子标记提供xml前缀
这是其中一个示例中提供的默认骆驼上下文当父级已经提供xml前缀时,我们是否需要为子标记提供xml前缀,xml,apache-camel,xml-namespaces,Xml,Apache Camel,Xml Namespaces,这是其中一个示例中提供的默认骆驼上下文 <?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"
<?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>
也许,我没有正确理解xml名称空间。如果您能详细解释名称空间如何作为奖金使用,我们将不胜感激。以下两个事实为您提供了答案:
- 子节点使用最近父节点的
声明xmlns
- 前缀文字(例如,
)并不重要-唯一重要的是它引用的名称空间。如果不同的前缀引用同一名称空间,它们可以交替使用,没有前缀也是前缀(空前缀)camel
因为您在
camel:camelContext
上的xmlns
声明引用了与xmlns:camel
声明相同的名称空间,所以是否省略这些子节点的camel:
并不重要,在这两种情况下,它们都将根据http://camel.apache.org/schema/spring
名称空间。因此,如果我理解正确,因为
定义了xmlns,没有任何前缀的子元素将继承该名称空间。因此,我是否可以跳过
本身中的驼峰前缀,因为它已经定义了xmlns是的,您可以。或者,您可以保留它,因为它可以提高可读性。
<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>