aspose file tools*
The moose likes XML and Related Technologies and the fly likes java and xml parser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "java and xml parser" Watch "java and xml parser" New topic
Author

java and xml parser

christophe seguinot
Greenhorn

Joined: Oct 19, 2007
Posts: 18
Hello,

I have an xml file which contains hundred of records. I need to store the java objects associated to these datas in a database. Which parser do you think I should use ? JAXB, SAX .... ??

Thanks a lot.

Chris
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
I think this topic would sit better on our XML forum. Moving thread.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

I would use the parser which is most convenient for you to program with, for such a small problem. Just pick one and get it done.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3097
    
  33

It also would depend on the operation you would be doing with your XML- Manipulating the XML or just parsing the XML. Depending on that you can choose either a DOM based parser or an event based parser.


Mohamed Sanaulla | My Blog
Leon Omk
Ranch Hand

Joined: Aug 17, 2010
Posts: 75



JAXB is my favorite, simple, elegant and pain-free, as good as castor.


OK, so that other guy knows Java better than I do, but I bet he can't speak Wuhanese(a Chinese Dialect) like me.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Yeah, JAXB is great as long as you have done the up-front design and created the schemas which make it work. But we don't know if that was done for Christophe's XML file.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3097
    
  33

Paul Clapham wrote:Yeah, JAXB is great as long as you have done the up-front design and created the schemas which make it work. But we don't know if that was done for Christophe's XML file.

Agree with Paul. You would require the schema to validate the XML.
Drew Liscomb
Greenhorn

Joined: Sep 20, 2010
Posts: 7
As Paul and Mohammed said, the kind of parser you use depends on your data, and what you want to do with it.

If you are "importing" an XML file with many "records" into a database, then you probably want an "event-based parser" like SAX or StAX. You can iterate through the file quickly, transferring the data into database tables. I see these parsers as more low-level, "close to the byte" tools to be used when you really want to crank through a boatload of data.

If you want to do more than this, then more object-based toolkits may be in order, like JAXB, XMLBeans, and Castor. Using these tools you end up with a Java object with the data from the XML. You can then do what you like with the data. One list is here: http://java-source.net/open-source/xml-parsers

I have used XMLBeans with good success, while JAXB would not compile the schema I needed. And yes, in my case, I have no control over the schema (.XSD and .WSDL files), and even less control over how well my source of XML conforms to it. Having said that, the "lazy object creation" claims I have seen about XMLBeans have not held up for me, and trying to read a large (~800MB) XML document used up all available memory and crashed.

Kind regards,
Drew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java and xml parser