Some of the XPath APIs doesn't work if the XML is not formatted.

-----Original Message-----
From: Claus Ibsen [mailto:claus.ib...@gmail.com]
Sent: Thursday, July 21, 2011 12:08 PM
To: users@camel.apache.org
Subject: Re: Reading XML file into a bean

When using XPath you should always mind namespaces. If your XML have a
namespace, then the XPath expression must have that namespace bound as
well.



On Wed, Jul 20, 2011 at 10:18 PM, dunnlow <dunn...@yahoo.com> wrote:
> I'd like to read XML files that will have some number of parameters defined
> for a bean and ultimately store the information into a database.
>
> Currently I am reading from a JMS queue and using a toJdbc method on my bean
> to create the sql to pass on to my database endpoint.  That works fine.  now
> I want to pull the same parameters out of XML files.
>
> It seems like this should be simple, but haven't had any luck.
>
> my toJDBC looks like..
>
> public String toJdbc(Exchange exchange){
>    Map<String,Object> theHeaders = exchange.getIn().getHeaders();
>    String theBody = exchange.getIn().getBody(String.class);
>    StringBuilder sb = ....
>       8<....
>    sb.append(((theHeaders.containsKey("age"))...
>    <build the rest of the jdbc string using theHeaders>
>     ...
>    return sb.toString();
>
> (but the problem seems to be with unmarshalling the XML file)
>
> Things I've tried:
> 1) "*file://c:/infile).beanRef("myBean","toJdbc").to("stream:out")*;
>    this grabs the file and loads the full XML text into the msg parameter
> of my jdbc (that method loads exchange.getIn().getBody into the msg
> parameter), which i suppose I could parse by hand.
>
> 2)
> *file://c:/infile).marshal().xtream().convertBodyTo(com.me.MyBean.class).beanRef("myBean","toJdbc")*
>    Hoping for some magic conversion, but no luck
>
> 3) I wrote a method for my bean with annotated XML parameters like:
>    public void fromXML(@XPath("/account/option/value") String value,
>   ....
>   System.out.println("value="+value);
>
>   But, value is always empty when i use the route:
>
>
> *file://c:/infile).marshal().xtream().beanRef("myBean","fromXML").to("stream:out");*
>
> So, my question is/are:
> 1) should #3 work?
>
> 2) Isn't there a better way?
>
> 3) Ideally, i'd like to parse the xml that comes in and NOT assume the XPATH
> is correct.  Do I need to do that myself?
>
> Thanks!
> -J
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Reading-XML-file-into-a-bean-tp4617160p4617160.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--
Claus Ibsen
-----------------
FuseSource
Email: cib...@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

***The information transmitted is intended only for the person or entity to 
which it is addressed and may contain confidential and/or privileged material. 
Any review,retransmission,dissemination or other use of, or taking of any 
action in reliance upon, this information by persons or entities other than the 
intended recipient is prohibited. If you received this in error, please contact 
the sender and delete the material from any computer.***

Reply via email to