CSC/ECE 517 Fall 2010/ch6 6g SL: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 30: Line 30:


== DOM vs SAX, JAXB, JDOM ==
== DOM vs SAX, JAXB, JDOM ==
DOM: Document Object Model
An object-based interface
Parser generates an in-memory tree corresponding to the document
DOM interface defines methods for accessing and modifying the tree
Advantages
* Very useful for dynamic modification of, access to the tree
* Useful for querying (I.e. looking for data) that depends on the tree structure [element.childNode("2").getAttributeValue("boobie")]
* Same interface for many programming languages (C++, Java, ...)
Disadvantages
* Can be slow (needs to produce the tree), and may need lots of memory
* DOM programming interface is a bit awkward, not terribly object oriented
JDOM: Java Document Object Model
A Java-specific object-oriented interface
Parser generates an in-memory tree corresponding to the document
JDOM interface has methods for accessing and modifying the tree
Advantages
* Very useful for dynamic modification of the tree
* Useful for querying (I.e. looking for data) that depends on the tree structure
* Much nicer Object Oriented programming interface than DOM
Disadvantages
* Can be slow (make that tree...), and can take up lots of memory
* New, and not entirely cooked (but close)
* Only works with Java, and not (yet) part of Core Java standard
SAX: Simple API for XML
An event-based  interface
Parser reports events whenever it sees a tag/attribute/text node/unresolved external entity/other
Programmer attaches “event handlers” to handle the event
Advantages
* Simple to use
* Very fast (not doing very much before you get the tags and data)
* Low memory footprint (doesn’t read an XML document entirely into memory)
Disadvantages
* Not doing very much for you -- you have to do everything yourself
* Not useful if you have to dynamically modify the document once it’s in memory (since you’ll have to do all the work to put it in memory yourself!)


== Conclusion ==
== Conclusion ==

Revision as of 17:31, 17 November 2010

Document Object Model

The Document Object Model is the language independent and platform independent interface which allows to interact with the document. Typically this interaction is with the objects of the HTML, XHTML and XML documents. DOM can change the content, style and structure of such documents. DOM API is provided in different languages to dynamically change XML and HTML documents.[1]

DOM structure

DOM in HTML, XML, Javascript

Models of programming language objects

The term object model can be used in two different contexts. In one sense; it refers to a collection of concepts used to describe the generic characteristics of objects particularly object oriented languages or its specifications. Over here it closely corresponds to the word data model. Examples of this can be Java object model. This contrasts with the object model used to describe collection of object classes used to model a particular system. A common application of this object model can be defined as the Document Object Model

Any object model has three key concepts

  • data structures that can be used to represent the object state
  • ways to associate behaviour with the object state
  • ways for the object methods to access and operate on that state

DOM vs Models of programming language objects

Other Competing Solutions

The Simple API for XML (SAX) is the event-driven, serial-access mechanism that does element-by-element processing. The API for this level reads and writes XML to a data repository or the web. SAX allows you to process a document as it's being read, which avoids the need to wait for all of it to be stored before taking action.

JDOM is a java representation of an XML document which makes it easy and efficient for reading and making changes to it. It has a straightforward API for Java programmers. It's an alternative to DOM and SAX, although it integrates well with both DOM and SAX. JDOM came into existance because of the following reasons.

  • DOM and SAX were not suffucient
  • SAX had no documentation and it often required building a state machine
  • DOM was defined in IDL, a lower denominator across languages and it felt foreigner to Java Programmers

DOM vs SAX, JAXB, JDOM

DOM: Document Object Model An object-based interface Parser generates an in-memory tree corresponding to the document DOM interface defines methods for accessing and modifying the tree Advantages

  • Very useful for dynamic modification of, access to the tree
  • Useful for querying (I.e. looking for data) that depends on the tree structure [element.childNode("2").getAttributeValue("boobie")]
  • Same interface for many programming languages (C++, Java, ...)

Disadvantages

  • Can be slow (needs to produce the tree), and may need lots of memory
  • DOM programming interface is a bit awkward, not terribly object oriented

JDOM: Java Document Object Model A Java-specific object-oriented interface Parser generates an in-memory tree corresponding to the document JDOM interface has methods for accessing and modifying the tree Advantages

  • Very useful for dynamic modification of the tree
  • Useful for querying (I.e. looking for data) that depends on the tree structure
  • Much nicer Object Oriented programming interface than DOM

Disadvantages

  • Can be slow (make that tree...), and can take up lots of memory
  • New, and not entirely cooked (but close)
  • Only works with Java, and not (yet) part of Core Java standard

SAX: Simple API for XML An event-based interface Parser reports events whenever it sees a tag/attribute/text node/unresolved external entity/other Programmer attaches “event handlers” to handle the event Advantages

  • Simple to use
  • Very fast (not doing very much before you get the tags and data)
  • Low memory footprint (doesn’t read an XML document entirely into memory)

Disadvantages

  • Not doing very much for you -- you have to do everything yourself
  • Not useful if you have to dynamically modify the document once it’s in memory (since you’ll have to do all the work to put it in memory yourself!)

Conclusion

References

  1. Document Object Model Introduction.