Spring Integration - XML processing
<p>I'm building an apllication that need to read and parse an XML file to start some jobs (each one based on the XML tag - below i show you an example of my XML, omitting the namespace).</p>

<p>Looking on SI project i've found this <a href="https://github.com/spring-projects/spring-integration-samples" rel="nofollow">example</a> that explain how to process XML file.</p>

<p>Before looking this i was trying to use a simple Unmarshalling process that create POJOS classes, this is good to parse it but many nested POJO will make my work very hard because for example some tags can be omitted (all are optional) and my program looks like an "infinite" <code>if-else</code>.</p>

<p>What i need to do is:</p>

<ul>
<li>Parse the file and for each tag start a JOB that make some operations</li>
</ul>

<p>Right now i dont want to think about the job (even using Spring i've seen Spring Batch and in the future i would like to integrate it with SI, but right now i just only need to parse the XML)</p>

<p>In the example i've seen that is used <code>si-xml:xpath-splitter</code>, so looking my XML file i will need to create many splitter for each tag and then redirect to an appropriate channel ? For example <code>process</code> tag will be redirected to appropriate <code>service-activator</code>, <code>activity</code> tag to another <code>service-activator</code> and so on ?</p>

<p>The example (the link i've show above) is a nice good start, but on the net i havent found other examples where i can "understand" other aspect of SI-XML, for this i've asked here for a little help on how to get started.</p>

<p>Another little problem is all attriutes that i have in the tags, with Unmarshalling i can create an interface and then i know that all classes must implement it (and use it to run the job), but here (SI + XML) i dont know how to create something similar...</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;root&gt;
    &lt;activity attr="1" /&gt;
    &lt;activity attr="2" /&gt;
&lt;/root&gt;
</code></pre>

<p><strong>UPDATE</strong>
Right now i've write this applicationContext in order to split each tag and redirect to appropiate channel but i'm having the error "<strong>Cannot convert #STRING in NodeList</strong>"</p>

<pre><code>&lt;si:channel id="rootChannel" /&gt;
    &lt;si:channel id="activityChannel" /&gt;
    &lt;!-- Here i split each tag of type activity --&gt;
    &lt;si-xml:xpath-splitter id="activitySplitter" input-channel="rootChannel" output-channel="router"&gt;
        &lt;si-xml:xpath-expression expression="//process|//activity" /&gt;
    &lt;/si-xml:xpath-splitter&gt;

     &lt;!-- Here i want route the messages to appropiate channel each tag must be processed separately because will need to create a thread for each one--&gt;
    &lt;si-xml:xpath-router input-channel="router"&gt;
        &lt;si-xml:xpath-expression expression="concat(name(./node()), 'Channel')" /&gt;
    &lt;/si-xml:xpath-router&gt;

    &lt;si:outbound-channel-adapter channel="activityChannel" method="dispatch"&gt;
        &lt;bean class="it.example.Activity" /&gt;
    &lt;/si:outbound-channel-adapter&gt;
</code></pre>

<p>This is the main class:</p>

<pre><code>public class Probe {
    public static void main(String[] args) throws Exception {
        AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/probeProcessing.xml", Probe.class);

        MessageChannel messageChannel = (MessageChannel) context.getBean("rootChannel");
        GenericMessage&lt;Document&gt; probeMessage = createXmlMessageFromResource("/META-INF/spring/probe.xml");
        messageChannel.send(probeMessage);

        context.close();
    }

    private static GenericMessage&lt;Document&gt; createXmlMessageFromResource(String path) throws Exception {
        Resource probeRes = new ClassPathResource(path);

        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        builderFactory.setNamespaceAware(false);
        DocumentBuilder builder = builderFactory.newDocumentBuilder();

        Document probeDoc = builder.parse(probeRes.getInputStream());
        return new GenericMessage&lt;Document&gt;(probeDoc);
    }
}
</code></pre>

<p>This is a part of the stack:</p>

<pre><code>Exception in thread "main" org.springframework.messaging.MessageHandlingException: error occurred in message handler [org.springframework.integration.config.RouterFactoryBean#0]; nested exception is org.springframework.xml.xpath.XPathException: Could not evaluate XPath expression:com.sun.org.apache.xpath.internal.XPathException: Impossibile convertire #STRING in NodeList.; nested exception is javax.xml.xpath.XPathExpressionException: com.sun.org.apache.xpath.internal.XPathException: Impossibile convertire #STRING in NodeList.
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:139)
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:231)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:154)
    at org.springframework.integration.splitter.AbstractMessageSplitter.produceOutput(AbstractMessageSplitter.java:156)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:102)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:105)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
    at it.dirimo.Probe.main(Probe.java:20)
</code></pre>