Re: torture
From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 06/04/04
- Next message: Oleg Konovalov: "Re: Java calling C# or VBA (MS Office API) ?"
- Previous message: Andrew Thompson: "Re: Classpath in java code ?!?"
- Maybe in reply to: KC Wong: "Re: torture"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Oleg Konovalov: "Re: Java calling C# or VBA (MS Office API) ?"
- Previous message: Andrew Thompson: "Re: Classpath in java code ?!?"
- Maybe in reply to: KC Wong: "Re: torture"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|