Re: torture

From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 06/04/04


Date: Fri, 04 Jun 2004 09:12:17 -0500

grahamo wrote:

> I have an XML document/string as an input parameter from which I need
> to
> extract some values.

If you're using Java 1.4 then you already have an XML parser built in to
your Java implementation. There are others available as third-party
modules as well. Look at the API docs for packages javax.xml.parsers,
org.xml.sax and subpackages, and org.w3c.dom.

The DOM API is conceptually easier -- it provides for a navigable,
manipulable object representation of the XML document in memory. It is
also slower and much heavier than the alternative (SAX).

The SAX API works by reading the document and generating callbacks to
user code at significant points (e.g. start of document, element start
tag, attribute, etc.). To use this interface you will need to write at
least one class to handle the callbacks of interest to you.

Programmers new to these API often become confused about how to get a
handle on an actual parser. The framework uses abstract factories for
both SAX and DOM, so the basic approach is something like

SAXParser parser = SAXParserFactory.newInstance().newSAXParser();

(For SAX; there is a similar setup for DOM.) Which one of SAX or DOM
you should use depends on your performance requirements and the
projected scale of the real XML files you will need to handle.
Requirements for high performance or large file handling favor SAX.

Contrary to another poster's assertion, you do not need to know anything
about XPath to parse XML documents.

John Bollinger
jobollin@indiana.edu



Relevant Pages

  • Re: XML Parser in EVC++ 4.0
    ... Excuse me can you give me some example for read my file XML with SAX ... parser in EVC++? ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: XmlTextreader versus DOM
    ... I've heard them referred to as "DOM" and "SAX". ... DOM is, generally speaking, the easiest way in which to deal with XML ... "SAX" (named after the original parser, I think) parsers read one XML ...
    (microsoft.public.dotnet.xml)
  • Re: [PHP] Good XML Parser
    ... So if I'm looking to parse certain attributes out of an XML tree, ... XML parsers fall into two general camps - DOM and SAX. ... If you just need the data, a SAX parser will probably do everything ...
    (php.general)
  • Re: XmlTextreader versus DOM
    ... I've heard them referred to as "DOM" and "SAX". ... DOM is, generally speaking, the easiest way in which to deal with XML ... "SAX" (named after the original parser, I think) parsers read one XML ...
    (microsoft.public.dotnet.languages.vc)
  • applet to applet - servlet model
    ... I have an applet which takes XML document and with help of SAX it finds ... Applet has three classes. ... Problem is that this applet takes data form XML document and the document is ...
    (comp.lang.java.programmer)