Hi,
I am trying to read a xml-file via the file component and I split and filter
the result and then change the dataformat from XML to JSON before sending it
out with the file component again.
I just can't seem to find a solution using Google or in my Camel In Action
book.
(My real world xml is totally different, but using a simple xml without
namespace for prototyping).
Input xml:
*<?xml version="1.0"?>
<root><a><id>1</id></a><a><id>2</id></a></root>
*My route:
*from("file:src/data/simple?noop=true").tracing()
.split(xpath("/root/a")).filter(xpath("/a/id[.='1']"))
.convertBodyTo(String.class).marshal()
.json(JsonLibrary.Jackson)
.to("file:target/messages?fileName=id1.json");*
Wanted output.json:
{a:{id:1}}
Result using Jackson:
"<a><id>1</id></a>"
(without the convertBodyTo: "<?xml version=\"1.0\"
encoding=\"UTF-16\"?>\n<a><id>1</id></a>")
Result using Xstream instead (and adding .convertBodyTo(String.class) before
marshalling)
{"string":"<a><id>1<\/id><\/a>"}
Seems as if I am missing some fundamental understanding of how things work?
How can I get my XML to be recognized as XML (which obviously the split and
xpath do)?
--
Brgds, Magnus Palmér
+46736845680