Re: Parsing XML
Re: Parsing XML
- Subject: Re: Parsing XML
- From: Kieran Kelleher <email@hidden>
- Date: Wed, 11 Feb 2009 08:13:23 -0500
Hi Josh Paul,
As you can see there are many ways to skin the XML parsing cat!
I found the book Processing "XML in Java" by Elliotte Rusty Harold
useful when I first started working with XML. YMMV.
If right now you need to get the job done quickly and your XML is
simple enough, then a SAX handler may be the quickest way to go.
At the lowest level XML parsing is done usually on of two ways, SAX-
style processing (fast and low memory) or DOM object model
representation of the XML. Higher level libraries such as WOXMLDecoder
use these lower level approaches to parsing the XML.
I will just explain how the SAX handler works in brief. Basically the
XML reader just reads the XML and identifies the element start and end
tags (for example a an element start tag being <tag1 id="45"> ) and
content inside the tags. As it walks the XML, it calls appropriate
methods in your handler, in effect telling you "now I have discovered
a start tag of an element and here I am calling your startElement
method of *your* handler and I am giving you all the information about
that start tag including the attributes (id = "3" etc.)
Based on the arguments your handler is given in the callback methods
you make decisions, whether those decisions are to create objects, set
boolean switches such as isCurrentlyInAnElementIAmInterestedIn = true
or whatever. So the XMLReader calls your startElement, endElement,
characters (aka content nested between element tags) methods as it
encounters them while parsing the XML file. All you have to do is
provide business logic to create whatever it is the XML represents for
you in your application.
HTH, Kieran
On Feb 11, 2009, at 5:56 AM, Alan Zebchuk wrote:
We generally use JAXB, nice if the xml is well defined and you can
write an xsd for it.
Alan
On 11-Feb-09, at 2:28 AM, Josh Paul wrote:
What libraries/methods do you use for parsing incoming XML (i.e.
via a REST call to an external service) and extracting values?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden