简体   繁体   English

使用.split()。tokenizeXML()在骆驼中拆分xml文件?

[英]Split xml file in camel using the .split().tokenizeXML()?

How to Split xml file in camel using the .split().tokenizeXML()? 如何使用.split()。tokenizeXML()在骆驼中拆分xml文件? I have attached the code snippet. 我已经附上了代码片段。 I dont know where I did mistake. 我不知道我在哪里做错了。 Here is my input. 这是我的意见。

<Record>
  <DataFile xmlns="Created">
  </DataFile>
  <DataFile xmlns="Updated">
  </DataFile>
  <DataFile xmlns="Deleted">
  </DataFile>
</Record>

Here is my camel route 这是我的骆驼路线

// Main Route
from(...)
.routeId("processor route")
.process(...)
.to("direct:created",
"direct:updated",
"direct:deleted").end();

// Created
from("direct:created")
.routeId("created route")
.split().tokenizeXML("xmlns:Created", "Record")
.to(...).end();

// Updated
from("direct:updated")
.routeId("updated route")
.split().tokenizeXML("xmlns:Updated", "Record")
.to(...).end();

// Deleted
from("direct:deleted")
.routeId("deleted route")
.split().tokenizeXML("xmlns:Deleted", "Record")
.to(...).end();

my expected output is ... direct:created should split and use this one only. 我的预期输出是... direct:created应该拆分并仅使用此一项。

<DataFile xmlns="Created">
</DataFile>

direct:updated should split and use this one only. direct:updated应该拆分并仅使用此选项。

<DataFile xmlns="Updated">
</DataFile>

and direct:deleted should split and use this one only. 和直接:删除应拆分并仅使用此选项。

<DataFile xmlns="Deleted">
</DataFile> 

You cannot split by namespace using the tokenizeXml. 您不能使用tokenizeXml按名称空间拆分。 You would need to split the file yourself, or write some code that can split by namespace. 您需要自己分割文件,或编写一些可以按名称空间分割的代码。

I don't know how to get value of "xmlns" attribute in XPath, because "xmlns" is a NameSpace attribute. 我不知道如何在XPath中获取“ xmlns”属性的值,因为“ xmlns”是NameSpace属性。 If you can change name of that attribute to eg "attribute" you can use something like this: 如果您可以将该属性的名称更改为“ attribute”,则可以使用如下所示的内容:

Firstly split xml to list of elements "DataFile", then use content-based routing using value of "attribute" ("attribute" because I don't know how to get value of "xmlns" attribute in XPath - you can find this yourself and try) 首先将xml拆分为元素“ DataFile”的列表,然后使用“ attribute”(“ attribute”)值进行基于内容的路由,因为我不知道如何在XPath中获取“ xmlns”属性的值-您可以自己找到并尝试)

from("direct:route").split().tokenizeXML("DataFile").streaming().choice()
    .when().xpath("//DataFile[@attribute=&#39;Created&#39;]").to("direct:created")
    .when().xpath("//DataFile[@attribute=&#39;Updated&#39;]").to("direct:updated")
    .otherwise().to("direct:deleted")

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

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