The big difference between SAX and DOM is that the xml is handed to you in the DOM and with SAX, you get it an event at a time. Since you apparently don't need to iterate over the XML more than once, SAX is the way to go.
For instance, if this is your XML:
<root> <data> real data </data> <data> more real data </data> </root>
You would get a call to the startElement method for 'root' and then another for the first 'data' followed by a call to the characters method with 'real data' followed by a call to the endElement method for 'data'. This repeats until all the "events" in the xml file have been reported.
It's a little more complicated than this (e.g., you would get characters calls for all the line feeds in my example above) but it's pretty straightforward and obviously uses a lot less memory than holding on to the XML in a DOM. It's probably faster for you, too.
John
At 12:25 PM 8/13/2004, Jones, Brian O. wrote:
I thought about using the SAX but I don't know alot about it and it might be easier to do it that way but I just don't know. I looked at SAXPrint example but that just prints the document is there a traverse method to sort thru and store the values...like I said I'm not familiar and I tried to read up on it, but seems like a lot of info for something not too difficult.
-----Original Message----- From: Jesse Pelton [mailto:[EMAIL PROTECTED] Sent: Friday, August 13, 2004 3:14 PM To: [EMAIL PROTECTED] Subject: RE: storing data from XML file into data structure
I'd consider using SAX rather than DOM for this, but it should be
straightforward to accomplish what you want with either. I think you
need to be specific about why you can't. A code fragment might help.
> -----Original Message-----
> From: Jones, Brian O. [mailto:[EMAIL PROTECTED]
> Sent: Friday, August 13, 2004 2:44 PM
> To: [EMAIL PROTECTED]
> Subject: RE: storing data from XML file into data structure
>
> I used several for loops to traverse down to the values that
> I want and I want to take the values and put them into my
> structure, but the section of the xml duplicates per entry
> (for example)
>
> struct Two
> {
> int value
> int number
> }
>
> struct One
> {
> int start
> int finish
> Two thisvar
> }
>
> So in my xml file struct one duplicates several times and two
> does as well so I but I know the order of data won't change.
>
> -----Original Message-----
> From: Jesse Pelton [mailto:[EMAIL PROTECTED]
> Sent: Friday, August 13, 2004 2:29 PM
> To: [EMAIL PROTECTED]
> Subject: RE: storing data from XML file into data structure
>
>
> If you can perform those two transformations (XML -> temp
> file and temp
> file -> structure), what prevents you from performing a single
> transformation (XML -> structure)? Presumably you've solved
> the problem
> of avoiding overwrites in the course of implementing serialization to
> and from your temp file. The same solution should apply if
> you omit the
> serialization and populate your structure as you parse.
>
> > -----Original Message-----
> > From: Jones, Brian O. [mailto:[EMAIL PROTECTED]
> > Sent: Friday, August 13, 2004 2:05 PM
> > To: [EMAIL PROTECTED]
> > Subject: storing data from XML file into data structure
> >
> > Hi all,
> >
> > I am trying to store all the contents of my xml file in a
> > structure when I parse the file, but each section of my file
> > is repeat and I don't want to overwrite what I already have.
> >
> > So my current solution is to parse the file and store the
> > information in a temp file and read the temp file and store
> > the information in my data structure.
> >
> > I just want to know if there is a better solution than the
> > one I've tried.
> >
> > Brian Jones
> > Senior Software Engineer
> > (Email) [EMAIL PROTECTED]
> > Phone (410) 993-2072
> > Fax (410) 981-8381
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]