Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath Camel中的消息拆分_Xpath_Apache Camel - Fatal编程技术网

Xpath Camel中的消息拆分

Xpath Camel中的消息拆分,xpath,apache-camel,Xpath,Apache Camel,我正在尝试编写一个camel路由,它将列表中的不同元素发送到不同的队列 消息正文将是一个包含2个xml的列表。例如: <Cat> <Name>Cat1</Name> </Cat>, <Dog> <Name>Dog1</Name> </Dog> 第一类 , 狗1 现在,我需要将消息的“Cat”部分(即Cat1部分)发送到queue1,将xml的“Dog”部分(即Dog1)发送到另一个队列 这是我的

我正在尝试编写一个camel路由,它将列表中的不同元素发送到不同的队列

消息正文将是一个包含2个xml的列表。例如:

<Cat>
<Name>Cat1</Name>
</Cat>,
<Dog>
<Name>Dog1</Name>
</Dog>

第一类
,
狗1
现在,我需要将消息的“Cat”部分(即Cat1部分)发送到queue1,将xml的“Dog”部分(即Dog1)发送到另一个队列

这是我的路线,但不起作用:

<route>
    <from uri="jms:queue:InQueue" />        
    <choice>
        <when>
            <simple>${in.body} regex 'Cat'</simple>
            <to uri="jms:queue:CatQueue" />
        </when>
        <when>
            <simple>${in.body} regex 'Dog'</simple>
            <to uri="jms:queue:DogQueue" />
        </when>
    </choice>
</route>

${in.body}regex'Cat'
${in.body}regex'Dog'

你知道我做错了什么吗?

首先,你必须使用
标记拆分列表。其次,必须使用XPath表达式解析XML部分,并将消息发送到适当的JMS队列:

<route>
    <from uri="jms:queue:InQueue" />
    <split>
        <tokenize token=","/>
        <log message="Working on split: ${body}" />
        <choice>
            <when>
                <xpath>/Cat</xpath>
                <to uri="jms:queue:CatQueue" />
            </when>
            <when>
                <xpath>/Dog</xpath>
                <to uri="jms:queue:DogQueue" />
            </when>
        </choice>
    </split>
</route>

/猫
/狗

将“Cat”xml正确路由到Cat队列。但是Dog xml根本没有被路由…它只是路由列表中的第一个元素(即cat)然后返回…根本不关心第二个元素(Dog)。我使用
Cat1,Dog1
作为输入字符串,一切都按预期进行。您在日志中看到以下输出了吗:
处理split:Cat1
处理split:Dog1
?我的错…我看错了…它工作了…谢谢…但是如果xmls中有名称空间呢…我必须更改什么来解释名称空间…例如:Cat1,Dog1得到了它…使用'/*[local-name()='Cat']“/Cat”的xpath中的”有效…再次感谢