I'm trying to make a program by using camel. This program should be able to recieve xml files in a folder called inbox_xml_files.
Then the program should get the text value of the < Country > element node inside the xml file.
If the text value is "Denmark" the file should be moved to a folder called "outbox_Denmark".
If the text value is "Sweden" the file should be moved to a folder called "outbox_Sweden".
If the text value is something else the file should be moved to a folder called "outbox_Other".
This is the XML file i use for testing:
<?xml version="1.0"?>
<Company>
<Employee>
<FirstName>Mike</FirstName>
<LastName>James</LastName>
<ContactNo>1234567890</ContactNo>
<Email>[email protected]</Email>
<Address>
<Country>Denmark</Country>
<City>Copenhagen</City>
<Zip>1234</Zip>
</Address>
</Employee>
</Company>
The camel xml file (The one I'm troubled with):
<camelContext id="camelId" xmlns="http://camel.apache.org/schema/spring">
<camel:route id="_route1">
<camel:from id="_from1" uri="file:C:/inbox_xml_files?noop=false"/>
<camel:choice id="_choice1">
<camel:when id="_when1">
<camel:xpath>
//Company/Employee/Address/Country = 'Denmark'
</camel:xpath>
<camel:to id="_to1" uri="file:C:/outbox_Denmark"/>
</camel:when>
<camel:when id="_when2">
<camel:xpath>
//Company/Employee/Address/Country = 'Sweden'
</camel:xpath>
<camel:to id="_to2" uri="file:C:/outbox_Sweden"/>
</camel:when>
<camel:otherwise id="_otherwise1">
<camel:to id="_to3" uri="file:C:/outbox_Other"/>
</camel:otherwise>
</camel:choice>
</camel:route>
</camelContext>
I believe that the problem is inside the < camel:xpath >. I think i have defined it wrong and i'm trying but all this is something new for me so i'm struggling with it.
Try this :
<camel:xpath>//Company/Employee/Address/Country='Sweden'</camel:xpath>
or
<camel:xpath>//*[local-name() = 'Country' and text()='Sweden']</camel:xpath>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With