Results 1 to 3 of 3
  1. #1
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default XML parsing with SAX

    I've searched how to parse XMLs with java, and I've have come to the conclusion that SAX is way better than DOM. I don't know how to use either of these, but I want to be able to parse XMLs. I have searched google many times for a simple tutorial, to no avail.

    Can someone please either explain how to use sax, or direct me to a good tutorial site? Any help is appreciated.

    EDIT: As hard and complicated as it sounds, I was thinking that creating a personalized parser class with custom, easy to understand methods and purposes. I would then just copy this class into whatever project I would be working on in which I would need to parse an XML. Is this a well-directed idea?
    Last edited by Prime624; 05-18-2013 at 11:07 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: XML parsing with SAX

    Using a SAX parser is easy if you have ploughed through the sometimes confusing documentation: first you have to configure a SAXParserFactory object which can create a SAXParser for you; you can set an extension of a DefaultHandler (a sort of fat callback function) to the SAXParser and make the parser parse the input. The callback function is called whenever necessary.

    While writing your own parser most certainly is doable but all the nitty-gritty work has been done already, so why do it again? Especially the validating parsers are tricky. My tip would be to start reading the API documentation for the SAXParserFactory and dig your way through.

    All that DOM stuff can come in handy if you want to structurally process the XML tree. Note that they have refitted the SAXParser stuff into the DOM stuff to do the parsing job.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,771
    Rep Power
    5

    Default Re: XML parsing with SAX

    Did you check out the tutorials in my signature. They devote a major section to XML parsing, with examples and when to use SAX vs DOM.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Parsing XML
    By techie in forum XML
    Replies: 2
    Last Post: 02-07-2011, 08:57 AM
  2. help with parsing
    By ace_03 in forum New To Java
    Replies: 15
    Last Post: 11-24-2009, 09:02 PM
  3. XML parsing using DOM
    By alley in forum XML
    Replies: 4
    Last Post: 10-14-2009, 06:17 PM
  4. Parsing XML
    By virvalid in forum Advanced Java
    Replies: 3
    Last Post: 08-10-2009, 12:40 PM
  5. Parsing
    By Matt Sakko in forum New To Java
    Replies: 14
    Last Post: 03-21-2009, 04:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •