XML Parsing - newbie question

  • Thread starter Marcio DeBarros
  • Start date
M

Marcio DeBarros

Hi,

This is my first time using XML.

I am working on an application using JDOM and SAX, and I need to get XML
documents back into the client side of my app and rebuild them into Java
classes/objects do be displayed by the GUI.

So far I know that I should use SAX to do that. However would be
helpfull to do some operations on these documents, like sorting,
seaching,etc... before I start creating my objects. So my question is
Does SAX(or any other parser) allows me manipulate the XML documents on
it before converting them into objects ? Or do I need to all that inside
my java programs after I get my classes parsed ?

Thanks in advance for any help or suggestions...

--MD
 
A

Aidan

Marcio said:
This is my first time using XML.

I am working on an application using JDOM and SAX, and I need to get XML
documents back into the client side of my app and rebuild them into Java
classes/objects do be displayed by the GUI.

So far I know that I should use SAX to do that. However would be
helpfull to do some operations on these documents, like sorting,
seaching,etc... before I start creating my objects. So my question is
Does SAX(or any other parser) allows me manipulate the XML documents on
it before converting them into objects ? Or do I need to all that inside
my java programs after I get my classes parsed ?


The normal approach would be to convert the documents to objects then sort
and maniplate the objects. But like any kind of data processing it really
depends of what you want to do and the resources at your disposal.

Before you can sort or search documents they have to have some kind of
representation in the program. SAX is not that helpful here since, a bit
like sorting on tape, it merely transforms an XML stream into a sequence of
parsing events. Supposing you had an XML document representing a list, then
you could build the object representation in a sorted form by assigning
slots based on the value of the events as they arrive. But that's really
more to do with object construction than with XML parsing.

A better approach would be to use a (J)dom parser which converts an XML
document to a tree representation - a DOM object. Once you have your DOM
object you can maniplate it using a XST transform or walk the DOM tree
programmatically.

You might also want to look at other XML to object mappings like jakarta
common's Digester and JAXB.

A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top