• 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

Default XML parser: SAX or DOM?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello:

When I created DOM object from an incoming XML stream (XML string), I use

DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = //incoming Stream
Document doc = db.parse(is);

As I learned that by default, the DocumentBuilderFactory uses the built-in XML parser that comes with JAXP. How do I know what type of XML parser that is? I think that I can try to look up the System Property "javax.xml.parsers.DocumentBuilderFactory" to see what parser class that is used as default. But, how can I know what type of parser it is? I mean is that a SAX parser or DOM parser?

Also, in Java there is a class SAXParser. it also has a overloaded parse method which takes various type of input parameters. How is this class being used? any samples that you can share? the parse method in SAXParser is defined with a void, which indicates not return anything, not like the parse method above from DocumentBuilder which returns a Document. I seem to have some confusion here.

Thank you.

-Rick
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I mean is that a SAX parser or DOM parser?



All DOM parsers are built on top of SAX parsers. Think about it - there is no other way to build a DOM - you have to look at every part of the input stream - in other words an SAX parser.

Bill
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic