You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "richie.riviere@gmail.com" <ri...@gmail.com> on 2013/10/11 06:40:27 UTC

Using StaX to parse xml document into database tables

Hi All,

I've just spent a few hours trying to implement a solution and am a bit
confused. My use case is that I have an XML document full of items. i.e.

<Items>...<item></item>...<item></item>...</Items>

There could be about 100 individual items in the document.

I am currently using StAXXPathSplitChoicePerformanceTest.java and
StAXJAXBIteratorExpressionTest.java as my guides to try and come up with a
good solution. The pattern I want to use is the message router pattern.

So far I have something like this...

MainApp.java <http://camel.465427.n5.nabble.com/file/n5741319/MainApp.java>  
ToStagingRouteBuilder.java
<http://camel.465427.n5.nabble.com/file/n5741319/ToStagingRouteBuilder.java>  
AbstractFileRouteBuilder.java
<http://camel.465427.n5.nabble.com/file/n5741319/AbstractFileRouteBuilder.java>  
Item.java <http://camel.465427.n5.nabble.com/file/n5741319/Item.java>  
application-context.xml
<http://camel.465427.n5.nabble.com/file/n5741319/application-context.xml>  
camel-context.xml
<http://camel.465427.n5.nabble.com/file/n5741319/camel-context.xml>  

The bit that reads the XML file from the input directory works. And I know
when my route runs and my processor does a String xml =
exchange.getIn().getBody(String.class); the xml in the file gets read
correctly.

Where I am stuck is that jaxb doesn't seem to have split the items into
individual item records.
i.e. This code returns empty and I get an array Index out of bounds.

/	protected void getObjects() {
        recordsEndpoint.expectedMessageCount(10);
        recordsEndpoint.allMessages().body().isInstanceOf(Item.class);
		Item item =
recordsEndpoint.getReceivedExchanges().get(0).getIn().getBody(Item.class);
		System.out.println(item.getItemNo());
	}/	

Does what I am doing in my code make sense. Can anyone help me with what I
am missing to get the parsing to work? 


Also if I do get the parsing of the xml file working can anyone provide me
some advice on a nice design pattern for me to use to write to the db. 


thank you!



--
View this message in context: http://camel.465427.n5.nabble.com/Using-StaX-to-parse-xml-document-into-database-tables-tp5741319.html
Sent from the Camel - Users mailing list archive at Nabble.com.