• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java and xml parser

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this topic would sit better on our XML forum. Moving thread.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 75
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


JAXB is my favorite, simple, elegant and pain-free, as good as castor.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic