简体   繁体   English

如何使用Apache Camel,java DSL,eclipse更改XML文件的内容

[英]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")

What do I want? 我想要什么?

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.

相关问题 将Apache Camel JSON数据格式从XML转换为Java DSL - Convert Apache Camel JSON data format from XML to Java DSL 如何在 Apache 的 Camel Spring DSL (XML) 路由中以简单语言调用 Java 方法中的正则表达式? - How to escape regex in Java methods call in simple language in Apache's Camel Spring DSL (XML) route? 如何在Apache Camel中使用REST DSL产生xml响应 - How to produce xml response using REST DSL in Apache Camel 使用apache-camel在Java中使用Tab分隔符获取SQL记录并将其写入文本文件(Spring和XML DSL文件除外) - Getting SQL records and write into text file with tab separated delimeter in Java using apache-camel (except Spring and XML DSL file) 如何包装长行的 Apache Camel Java DSL 代码 - How to wrap long lines of Apache Camel Java DSL code 如何获取Apache骆驼中的DSL(特定域语言)列表? - How can I get list of DSL(Domain Specific Language) in apache camel? 在Java DSL上使用Java和Spring代码的Apache Camel - Apache Camel with Java and Spring Code on Java DSL 如何使用Apache Camel正确聚合文件内容? - How do I aggregate file content correctly with Apache Camel? Java DSL中的Apache Camel URI过滤器 - Apache Camel URI filter in Java DSL Apache Camel Java DSL 向正文添加换行符 - Apache Camel Java DSL add newline to body
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM