hi I started learning google data api. I have one question What will be the best way of parsing xml google data xml ?
1 > Should I go with manually parsing xml ?
Or
2 > XML to java object mapping technique ?
I am thinkin开发者_如何学运维g about going with 2 way, As it will require writing less code from my side. But I don't know how slow it will be in comparison to 1 way.
How slow is xml to java mapping technique ?
Is there any other better way to parse gdata xml ?
How slow is xml to java mapping technique ?
The answer to this question depends on what you are comparing the xml to Java mapping technique to. Many object-to-XML solutions have been around for quite a while and have learned a number of tricks to do this conversion.
Is there any other better way to parse gdata xml ?
Note: I'm the EclipseLink JAXB (MOXy) lead, and a member of the JAXB (JSR-222) expert group.
I'm not that familiar with the Google Data API, but after a quick google, it appears to be related to Atom which can easily be handled by any of the JAXB implementations:
- Metro (reference implementation included in Java SE 6)
- EclipseLink JAXB (MOXy)
- Apache JaxMe
For an Atom example see:
- http://bdoughan.blogspot.com/2010/09/processing-atom-feeds-with-jaxb.html
With JAXB you can also start with your own object model and add annotations to apply the XML mapping:
- http://bdoughan.blogspot.com/2010/11/jaxb-and-inheritance-using-substitution.html
- http://bdoughan.blogspot.com/2010/10/jaxb-and-xsd-choice-xmlelements.html
- http://bdoughan.blogspot.com/2010/09/jaxb-collection-properties.html
MOXy also contains an XPath mapping extension that makes mapping your object model even easier:
- http://bdoughan.blogspot.com/2010/09/xpath-based-mapping-geocode-example.html
Take a look at Caster project. Judging from your question, i don't think you would want to go though the trouble to parse the XML using the correct schema and create POJO's to match them (which is troublesome anyway).
I used Caster sometime ago, it is not the best, but got my problem solved pretty fast.
http://www.castor.org/
精彩评论