简体   繁体   English

我如何在Apache Camel中使用xpath获取nodeList

[英]How can i get nodeList using xpath in Apache Camel

I have an xml like 我有一个像

<Response>
    <Status>
        <Code>0</Code>
    </Status>
    <Order>
        <OrderId>1</OrderId>
    </Order>
</Response>

How can i get all the nodes instead Response, but without the tag 如何获取所有节点而不是响应,但是没有标签

When i try this, I get the entire xml 当我尝试这个时,我得到了整个xml

<xpath>/Response</xpath>

When i try this, the output is blank 当我尝试这个时,输出为空白

<xpath>/Response/text()</xpath>

What can i do so I only get this, with the outer tag 我该怎么办,我只能用外部标签得到

   <Status>
        <Code>0</Code>
    </Status>
    <Order>
        <OrderId>1</OrderId>
    </Order>

It is not clear if the desired output is the XML without the document element or if you want all of the text from within the XML. 尚不清楚所需的输出是没有文档元素的XML还是要从XML内获取所有文本。

If you want the sequence of child elements, then you would want: 如果需要子元素的顺序,则需要:

/Response/*

If you want the You could use the string() function to get the computed text value of the /Response element: 如果需要,可以使用string()函数获取/Response元素的计算文本值:

string(/Response)

If that happens to include some unwanted carriage returns and whitespace, due to the XML being pretty-printed, you could use normalize-space() , which will collapse repeated whitespace: 如果由于XML的漂亮打印而碰巧包含一些不必要的回车符和空格,则可以使用normalize-space() ,它将折叠重复的空格:

normalize-space(/Response)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM