Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML with SAX or DOM

Status
Not open for further replies.

michaenh

Programmer
Aug 7, 2002
205
NO
Just woundering anyone have any good ideas..

I am trying to manipulate xml documents... get data and export data. So I found that I could do it with DOM or SAX ...

What is the best way DOM or SAX? And why? Differences?

Many help and many thanks

mha
 
Hi

For interested people..

SAX:
SAX doesn't create a tree for XML nodes. It is a event based API provides a simpler, lower-level access to an XML document. Parses documents much larger than your available system memory.

DOM:
Tree based API. Map an XML document into an internal tree structure, then allow an application to navigate that tree.

Conclusion:
Use DOM to create XML documents and use SAX(fire events) to get XML data.

Next step -> SOAP and Webservices or .NET solutions..

mha
 
Weird - I've just been reading that section in Mastering Delphi 6 by Marco Cantu! I think you've now answered your own question, yes?

I'm looking at XML techniques in order to parse an HTML document i.e. extract data, ignoring the tags.

I've just been looking at one of the examples that comes with the book (the XmlEditOne example) and it won't run because it can't find xmldom which is in the uses list.
Do you know how to get access to this unit?

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
hehe.. yes I have now answered my own question...

I am developing myself.. eager to learn from experts and forums like this one...

What kind of Delphi version do you have?

I could send you the xmldom.pas. Its also enough with xmldom.dcu and put it in your Lib directory where Borland Delphi is installed.

mha

 
I am now using Delphi7, but it should have been there with Delphi6. I am almost certain...

ex.:
C:\Program Files\Borland\Delphi7\Source\Xml

mha
 
Maybe there are some differences between enterprise and pro versions.. ?

mha
 
I checked in the equivalent path and I have no XML folder in my Source folder. I did a bit of digging and it looks like I just need to download an update pack. So I'll then be able to access the dcu's mentioned in the book.

Cheers for your help

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
You are always welcome.

Yes I remmeber that I have update my Delphi's...

Great.. keep in touch about .net and soap if you find anything special info.

mha

 
Another way to think about it is:

DOM reads the whole document; you can navigate around and explore the relationship between parent and child elements, but it can use a lot of memory and take a long time.

SAX is small: it fires an event every time it reads an element; the event handler does something with the element; and then the element is gone.

I wrote an XML parser that fires Begin and EndElement events so the event handler can free the elements instead of only letting it have one shot at it. This lets me keep small hierarchies in memory so I can navigate, count the number of children, etc. without having to hold the whole thing.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top