[英]How can I change the content of XML file with Apache Camel, java DSL, eclipse
I have a XML file, which is named input-kunde-2.xml. 我有一个XML文件,名称为input-kunde-2.xml。
from("file:c:/test/?fileName=input-kunde-2.xml")
<?xml version='1.0' encoding='UTF-8'?>
<list>
<Name>Ying</Name>
<Age>23</Age>
</list>
And i have used Apache Camel route this file from C:/ into another place D:/. 我已经使用Apache Camel将这个文件从C:/路由到另一个地方D:/。
to("file:d:/test/?fileName=output-kunde-2.xml")
Now, i want change the content of XML file. 现在,我想更改XML文件的内容。
In the file input-kunde-2.xml: <Name>Ying</Name>
在文件input-kunde-2.xml中:
<Name>Ying</Name>
In the file output-kunde-2.xml: <Name>Wang</Name>
在文件output-kunde-2.xml中:
<Name>Wang</Name>
How can I implement it? 我该如何实施? Ich have try to use:
可以尝试使用:
File body = exchange.getIn().getBody(File.class);
//KundeDTO kundeDTO = exchange.getIn().getBody(KundeDTO.class);
But i could only get the path of the XML file. 但是我只能得到XML文件的路径。
Thanks a lot! 非常感谢!
If you are wanting to extract values from the file, treat it as an XML document and make use of xpath 如果要从文件中提取值,请将其视为XML文档并使用xpath
For instance with 例如与
.setHeader("myHeader").xpath("/list/Name/text()", String.class)
This documentation is here http://camel.apache.org/xpath.html 该文档在此处http://camel.apache.org/xpath.html
If you want to modify an entire XML document, then make use of XSLT. 如果要修改整个XML文档,请使用XSLT。 Consume your file with 'from', then pass it through the XSLT component, then send it to your file location
使用“来自”来使用文件,然后将其通过XSLT组件,然后将其发送到您的文件位置
This documentation is here http://camel.apache.org/xslt.html 该文档在此处http://camel.apache.org/xslt.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.