• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Are SAX and DOM Parsers or APIs???

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
I am highly confused as to wether DOM and SAX are parsers or APIs to support XML coz when we talk about parsers we talk about wether it supports SAX or DOM but again when we talk about the two type of parsers we talk about stream based or document which are implemented by Please help
Amit Roy
[This message has been edited by Amit Roy (edited June 02, 2001).]
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

IMO, these are API's. The parsers (JAXP, xerces etc)
implement the API's (mostly interfaces).
I hope someone will correct me if I am wrong.....
regds.
- sayta
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Satya, you are right. Both DOM and SAX are generic APIs for XML. The difference between two:
1) DOM is tree-based and SAX is event-based;
2) DOM is �official� W3C specification, whereas SAX is a product of XML developer community, led by David Megginson. He, by the way, had plans to resign, and it was discussed if SAX API should be passed to W3C. So maybe in the future SAX will obtain an official status too.
�DOM parser� and �SAX parser� are, IMHO, a short way of saying �a parser implementing DOM/SAX API�.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To add to what has been said alreay, many of the parsers available today support both DOM and SAX based parsing. Since DOM is a W3 spec, just like any evolving specification, it has undergone quite a lot of changes. DOM Level II and Level III offer more sophisticated document handling and is unquestionably poised to surpass the popularity and flexibility of SAX.
Not to forget, XSLT transformations are DOM based .....
 
Amit Roy
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it that we can use dom to write both C++ and java Programs is thr something like DOM API for Java and a DOM API for C++ or is it the same.What i have heard that in the DOM Model we can make objects that correspond to the tree structure of the XML tree and if we want to manipulate any data we can manipulate these objects which in turn manipulates the XML file which in turn manipulates the Database .(this is when we are using XML as a data cache in a system) I have no idea wether what i am saying is right please correct me if i am wrong
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

WOW!
Amit:
I suggest you take one step at a time.
There seem to be too many assumptions that you are
making when you say "in turn manipulates...in turn
manipulates..."
.
DOM can be implemented any way you want (Java or C++).
DOM is (as you said) a way to represent data in
a Cache. Esp hierarchial data. Yes, you can manipulate
the data. And to store in a Database, you have to support
other methods which take the manipulated data from your
DOM tree structure and write it to the DB.
ps: DOM does not specify how you generate your data or
how you store it. If only specifies how it is represented
in a tree structure.
Hopefully we can hear more from Ajith/Map....
- satya

 
Amit Roy
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then what is used to put the manupilated data into the database??
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's try and pin this down a bit.
SAX is the "Simple API for XML". Sax is a Java API for stream-based parsing of XML input. Most available Java XML parsers implement one or more versions of the SAX API.
Programs which use SAX are "callback"-based. A program uses the SAX API to register interest in specific tags and/or content, then invokes the parser. The parser runs through the XML stream from start to finish and calls your code whenever information in which you are interested is encountered. It is up to your program to build internal data structures, generate output or whatever else is needed - a SAX parser just lets you know that some data is there.
DOM is the "Document Object Model". DOM is a (largely) language independent model for how an XML doceument can be represented in memory. DOM is defined in terms of a set of operations which may be performed on a document. The precise details of how these operations are performed, and how the document data is actually stored in memory are up to the implementer of the parser and depend to some degree on the language chosen to implement the parser and the API.
DOM was designed by a commitee to be language independent, so it has to provide operations which can be implemented in a variety of languages. This means that using the DOM API can sometimes seem clumsy and unusual in any particular language. A lot of Java DOM parsers are actually implemented using SAX. The DOM parser uses the SAX API to register interest in all elements and content, then as the incoming data stream is parsed by the SAX-parser, the DOM parser catches the tags and content and builds the DOM data structures in memory.
A program which uses the DOM API typically "gulps" a whole XML file or stream into a DOM "Document" object, then traverses it looking for particular elements, attributes or content and performing operations on them or with them.
JDOM is a "Java Document Object Model". Designed to make using XML documents simpler for Java programmers, it performs a similar job to DOM, but in a java-specific way. If you want to write your own Java programs to manipulate XML documents, using JDOM is often a lot easier than using the language-neutral DOM API.
There are lots of parser implementations available, including Xerces, xml4j and so on. Many have no particular names, and are just built-in to other products such as the Resin web server. Sometimes a developer will not be sure which parser to choose and want to try several before deciding, which is where JAXP comes in.
JAXP is the "Java API for XML Parsing" from Sun. It provides a way to write programs which are independent of any particular parser implementation, and abstracts operations like starting a parser, telling it what to parse, and shutting it down when you have finished into a consistent API. JAXP is not a parser. Sun do provide an implementation of a SAX and DOM parser, which is often downloaded and installed with JAXP, but JAXP is really just a way to avoid rewriting your program every time you want to check out a new parser.
XSLT is a stylesheet specification language which allows you to write an XML definition of a transformation of an XML document into some other format. XSLT tools are often used to apply a particular look-and-feel to a simple XML document to make a complex HTML page for display on a web site, but XSLT is also capable of far more powerful transformations. To perform an XSLT transformation you need an XSLT processor. Some recent browsers have XSLT processors built-in, but the vast majority of XSLT processing is done on servers.
XSLT is its own language, so there is not really an XSLT API in the same way as there is for DOM and SAX. The only operations needed are usually starting the XSLT processor, telling it which stylesheet to use, and processing one or more documents. At present there is no equivalent to JAXP for XSLT processors, so if you want to directly use XSLT in this way you will most likely tie your code to a particular vendor's XSLT processor implementation.
As for databases. XML is essentially just a data interchange format, which happens to have some increasingly standardized tools available for it. It has no more to to do with databases than any other aspect of programming.
 
Amit Roy
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well Frank
Your post cleared many of the myths i had 1 more particular question i have is that when we are takin about XML as a data Cache then what is the tool that is used to extract data from the database and put in into the xml file.
And if some 1 can give a detailed explanation of the entire architecture where in the xml is used as a data cache it would be most welcomed. Is there a way where in i can display a image in my post?
[This message has been edited by Amit Roy (edited June 05, 2001).]
[This message has been edited by Amit Roy (edited June 05, 2001).]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic