28
SDPL Notes 3.3: DOM Examples 1 3.3 DOM Examples 3.3 DOM Examples 1. DOM processing in a Web 1. DOM processing in a Web browser browser a toy "XML database browser" a toy "XML database browser" with JavaScript and MS Internet with JavaScript and MS Internet Explorer Explorer 2. Stand-alone DOM processing 2. Stand-alone DOM processing creating and updating XML files creating and updating XML files with Java and SUN JAXP with Java and SUN JAXP implementation of DOM implementation of DOM

SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

Embed Size (px)

Citation preview

Page 1: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 1

3.3 DOM Examples3.3 DOM Examples

1. DOM processing in a Web browser1. DOM processing in a Web browser– a toy "XML database browser"a toy "XML database browser"– with JavaScript and MS Internet Explorerwith JavaScript and MS Internet Explorer

2. Stand-alone DOM processing2. Stand-alone DOM processing– creating and updating XML filescreating and updating XML files– with Java and SUN JAXP implementation with Java and SUN JAXP implementation

of DOMof DOM

Page 2: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 2

A Very Short Introduction to JavaScriptA Very Short Introduction to JavaScript

a simple a simple object-orientedobject-oriented scriptingscripting language language

– for computations in a host environment (e.g. a for computations in a host environment (e.g. a browser or a server)browser or a server)

– depends on depends on host objectshost objects for central tasks like input for central tasks like input and outputand output

– used to manipulate, customise and automate used to manipulate, customise and automate facilities of an existing systemfacilities of an existing system

originally a Web scripting languageoriginally a Web scripting language– core language independent of host environmentscore language independent of host environments– standardised version called ECMAScript (Aug. standardised version called ECMAScript (Aug.

1998)1998)

Page 3: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 3

Basic components of JavaScript Basic components of JavaScript

ObjectsObjects: collections of : collections of propertiesproperties::– other objects, primitive values, or methodsother objects, primitive values, or methods– Methods: Methods: functions associated to an objectfunctions associated to an object

Primitive valuesPrimitive values– Undefined,Undefined, Null,Null, numbers (ints and floats)numbers (ints and floats)– Strings:Strings: "Hi world!", 'Type "Y" for "Hi world!", 'Type "Y" for yes'yes'

– BooleansBooleans true true andand false false » true != 1true != 1 andand false != 0false != 0, , butbut » if (1)if (1) andand if (2)if (2) succeedsucceed , , whilewhile if (0)if (0) failsfails

Page 4: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 4

Syntax, data types and variablesSyntax, data types and variables

JavaScript syntax resembles JavaJavaScript syntax resembles Java JavaScript is loosely typedJavaScript is loosely typed

– variables need not be declared; variables need not be declared; normally created by assigning a valuenormally created by assigning a value

Global and local variables:Global and local variables:

functionfunction newFunction() newFunction(){ { varvar loop=1; loop=1; // local variable// local variable

total=0;total=0; // global variable// global variable ...additional statements......additional statements... }}

Page 5: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 5

Web Scripting in a BrowserWeb Scripting in a Browser

The client-side host environment providesThe client-side host environment provides– objectsobjects for UI components: windows, menus, pop- for UI components: windows, menus, pop-

ups, dialog boxes, text areas, anchors, frames, ups, dialog boxes, text areas, anchors, frames, history, cookies, and input/output history, cookies, and input/output

– means to attach scripting code to means to attach scripting code to eventsevents » actions occurring on the Web page:actions occurring on the Web page:

mouse actions, page and image loading, mouse actions, page and image loading, selection, form submission,…selection, form submission,…

Scripting code resides in the HTML pageScripting code resides in the HTML page– reactive to user interaction; reactive to user interaction;

no need for a main programno need for a main program

Page 6: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 6

Event HandlersEvent Handlers

Scripts normally Scripts normally event-driven, event-driven, triggered by triggered by actions on the Web pageactions on the Web page

Event handlers attached to elements Event handlers attached to elements corresponding to UI objects which notify events:corresponding to UI objects which notify events:

<tagName attr1="…" attr2="…" ...<tagName attr1="…" attr2="…" ...ononEventNameEventName="JavaScript code;">="JavaScript code;">

Events part of the DOM Events part of the DOM – standardised in DOM Level 2standardised in DOM Level 2

Page 7: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 7

Some Common Events & HandlersSome Common Events & Handlers

clickclick & & onClickonClick (on a form element or link) (on a form element or link)

changechange & & onChangeonChange (of text, textarea, or select (of text, textarea, or select element) element)

focusfocus & & onFocusonFocus and and blurblur & & onBluronBlur: : – input focus given to or removed from a form elementinput focus given to or removed from a form element

loadload & & onLoadonLoad and andunloadunload & & onUnloadonUnload – User loads or exits the pageUser loads or exits the page

Page 8: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 8

A JavaScript-DOM exampleA JavaScript-DOM example

A simple database browserA simple database browser Technical basisTechnical basis

– msxml parser included in MS IE 5 browsermsxml parser included in MS IE 5 browser– exposes XML documents to JavaScript as exposes XML documents to JavaScript as

a DOM-compliant ActiveX objecta DOM-compliant ActiveX object

Page 9: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 9

DOM example: UI framesDOM example: UI frames

The UI consists of two HTML frames: one for The UI consists of two HTML frames: one for control buttons, the other for displaycontrol buttons, the other for display

<HTML><HEAD><HTML><HEAD> <TITLE>XML DOM Database viewer</TITLE><TITLE>XML DOM Database viewer</TITLE></HEAD></HEAD> <FRAMESET COLS="*,2*"> <!-- 1/3 of width for<FRAMESET COLS="*,2*"> <!-- 1/3 of width for

controls frame and 2/3 for display frame -->controls frame and 2/3 for display frame --> <FRAME SRC="controls.html"><FRAME SRC="controls.html"> <FRAME ID="display" SRC="display.html"><FRAME ID="display" SRC="display.html">

<!-- an originally empty HTML page --><!-- an originally empty HTML page --> </FRAMESET></FRAMESET></HTML></HTML>

Page 10: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 10

The Example Database FileThe Example Database File

<?xml version="1.0" encoding="ISO-8859-1" ?><?xml version="1.0" encoding="ISO-8859-1" ?>

<db><person <db><person

idnum="1234"><lastidnum="1234"><last

>Kilpeläinen</last><first>Pekka</first></>Kilpeläinen</last><first>Pekka</first></person>person>

<person idnum="5678"><last<person idnum="5678"><last

>Möttönen</last><first>Matti</first></person>>Möttönen</last><first>Matti</first></person>

<person idnum="9012"><last<person idnum="9012"><last

>Möttönen</last><first>Maija</first></person>>Möttönen</last><first>Maija</first></person>

<person idnum="3456"><last<person idnum="3456"><last

>Römppönen</last><first>Maija</first></person>>Römppönen</last><first>Maija</first></person>

</db></db>

Page 11: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 11

Main data structures (Script begins)Main data structures (Script begins)

In In controls.htmlcontrols.html::<SCRIPT LANGUAGE="JScript"> <SCRIPT LANGUAGE="JScript">

<!-- // Script begins; Variables:<!-- // Script begins; Variables:

var var xmldocxmldoc = new = new ActiveXObject("Microsoft.XMLDOM");ActiveXObject("Microsoft.XMLDOM");

var displStr; /* string for HTML var displStr; /* string for HTML

display of xmldoc */display of xmldoc */

var current; // index of current rowvar current; // index of current row

var displayFrame; var displayFrame;

var persons;var persons; /* list of person elements /* list of person elements

in xmldoc */in xmldoc */

Page 12: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 12

Body of the controls frameBody of the controls frame

<BODY onLoad="initFrames()"> <BODY onLoad="initFrames()">

<!-- Slightly simplified! --><!-- Slightly simplified! -->

<H2>XML DOM Database Viewer</H2><H2>XML DOM Database Viewer</H2>

<B>Enter the location of the XML file: </B><B>Enter the location of the XML file: </B>

<INPUT ID="XMLFile" TYPE="text" SIZE="30" <INPUT ID="XMLFile" TYPE="text" SIZE="30"

VALUE="db.xml"></INPUT>VALUE="db.xml"></INPUT>

<INPUT TYPE="button" onClick="loadXML()"<INPUT TYPE="button" onClick="loadXML()"

VALUE="Load XML and Display DB"></INPUT>VALUE="Load XML and Display DB"></INPUT>

<BUTTON onClick="displayDB()"><BUTTON onClick="displayDB()">

Refresh Display</BUTTON>Refresh Display</BUTTON>

<!-- Show XML button omitted ... --><!-- Show XML button omitted ... -->

Page 13: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 13

Controls Frame: navigation buttonsControls Frame: navigation buttons

<BUTTON OnClick="if (persons==null) <BUTTON OnClick="if (persons==null)

alert('Empty database'); alert('Empty database');

else { if ( checkPrev(persons,current) ) else { if ( checkPrev(persons,current) )

showPerson(--current); showPerson(--current);

else alert('At the first else alert('At the first person') }">person') }">

Previous Person</BUTTON>Previous Person</BUTTON>

<BUTTON OnClick="if (persons==null) <BUTTON OnClick="if (persons==null)

alert('Empty database'); alert('Empty database');

else {if ( checkNext(persons,current) ) else {if ( checkNext(persons,current) )

showPerson(++current); showPerson(++current);

else alert('No more persons') }">else alert('No more persons') }">

Next Person</BUTTON>Next Person</BUTTON>

</BODY></BODY>

Page 14: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 14

Helper functions (Script continues)Helper functions (Script continues)

functionfunction initFrames() // on load initFrames() // on load

{{ displayFrame = parent.display;displayFrame = parent.display;

displayFrame.document.open();displayFrame.document.open();

displayFrame.document.write(""); displayFrame.document.write(""); displayFrame.document.close();}displayFrame.document.close();}

functionfunction checkPrev(list, index) checkPrev(list, index)

{ return (index > 0); }{ return (index > 0); }

functionfunction checkNext(list, index) checkNext(list, index)

{ return (index < list.{ return (index < list.lengthlength - 1);} - 1);}/* DOM Core features /* DOM Core features emphasisedemphasised */ */

Page 15: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 15

DB Viewer: XML loadingDB Viewer: XML loading

functionfunction loadXML(){ loadXML(){ ……

xmldoc.load(XMLFile.value);xmldoc.load(XMLFile.value);

ifif (xmldoc. (xmldoc.documentElementdocumentElement != null) { != null) {

persons= persons= xmldoc.xmldoc.getElementsByTagName("person")getElementsByTagName("person");;

current = 0;current = 0;

displayDB();displayDB();

}}

}}

Page 16: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 16

Generating the HTML display (1)Generating the HTML display (1)

functionfunction displayDB(){ //... displayDB(){ //...

// addhtml() collects result to displStr // addhtml() collects result to displStr

displStr = ""; displStr = "";

varvar rows = rows =

xmldoc.xmldoc.documentElement.childNodesdocumentElement.childNodes;;

addhtml('<TABLE>');addhtml('<TABLE>');

forfor (var i = 0; i < rows. (var i = 0; i < rows.lengthlength; i++) {; i++) {

// generate HTML for each row; // generate HTML for each row;

// See loop body below// See loop body below

Page 17: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 17

Generating the HTML display (2)Generating the HTML display (2)

varvar currRow = rows. currRow = rows.item(i)item(i);;

addhtml('<TR>'); addhtml('<TR>');

addhtml('<TD>' + ((i == current)?'*** ':' ') + addhtml('<TD>' + ((i == current)?'*** ':' ') + '</TD>'); // print stars in front of current '</TD>'); // print stars in front of current addhtml('<TD>' + currRow.addhtml('<TD>' + currRow.getAttribute("idnum")getAttribute("idnum")

+ '</TD>');+ '</TD>');

addhtml('<TD>' + // contents of element ‘last’addhtml('<TD>' + // contents of element ‘last’

currRow.currRow.firstChild.firstChild.nodeValuefirstChild.firstChild.nodeValue + + '</TD>');'</TD>');

addhtml('<TD>' + // contents of element ‘first’addhtml('<TD>' + // contents of element ‘first’

currRow.currRow.lastChild.firstChild.nodeValuelastChild.firstChild.nodeValue + +

'</TD>');'</TD>');

addhtml('</TR>'); }; // end loop through rowsaddhtml('</TR>'); }; // end loop through rows

Page 18: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 18

Generating the HTML display (3)Generating the HTML display (3)

// Complete the HTML display:// Complete the HTML display:addhtml('</TABLE>');addhtml('</TABLE>');displayFrame.document.open();displayFrame.document.open();displayFrame.document.write(displStr); displayFrame.document.write(displStr); displayFrame.document.close();displayFrame.document.close();

} // end displayDB()} // end displayDB()

// Wrapper for displaying current person:// Wrapper for displaying current person:functionfunction showPerson(pers){ showPerson(pers){displayDB()displayDB() // simply display all// simply display all

}}

Page 19: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 19

A Java-DOM exampleA Java-DOM example

A stand-alone toy application A stand-alone toy application BuildXmlBuildXml– either creates a new either creates a new dbdb document with two document with two personperson elements, or adds them to an existing elements, or adds them to an existing dbdb documentdocument

– based on the example in Sect. 8.6 of based on the example in Sect. 8.6 of Deitel et al: Deitel et al: XML - How to programXML - How to program

Technical basisTechnical basis– DOM support of the Java-based JAXP XML DOM support of the Java-based JAXP XML

processor implementationprocessor implementation– native XML document initialisation and storage native XML document initialisation and storage

methods of the JAXP 1.1 default parser (Apache methods of the JAXP 1.1 default parser (Apache Crimson)Crimson)

Page 20: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 20

Code of Code of BuildXmlBuildXml (1) (1)

Begin by importing necessary packages:Begin by importing necessary packages:

import java.io.*;import java.io.*;

import org.w3c.dom.*;import org.w3c.dom.*;

import org.xml.sax.*;import org.xml.sax.*;

import javax.xml.parsers.*;import javax.xml.parsers.*;

// Native (parse and write) methods of the// Native (parse and write) methods of the

// JAXP 1.1 default parser (Apache Crimson):// JAXP 1.1 default parser (Apache Crimson):

import org.apache.crimson.tree.XmlDocument;import org.apache.crimson.tree.XmlDocument;

Page 21: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 21

Code of Code of BuildXmlBuildXml (2) (2)

Class for modifying the document in file Class for modifying the document in file fileNamefileName::

public class BuildXml {public class BuildXml { private Document document;private Document document;

public BuildXml(String fileName) {public BuildXml(String fileName) { File docFile = new File(fileName);File docFile = new File(fileName); Element root = null; // doc root elemenElement root = null; // doc root elemen

// Obtain a SAX-based parser:// Obtain a SAX-based parser: DocumentBuilderFactory factory =DocumentBuilderFactory factory =

DocumentBuilderFactory.newInstance();DocumentBuilderFactory.newInstance(); DocumentBuilder builder; /* … */DocumentBuilder builder; /* … */

Page 22: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 22

Code of Code of BuildXmlBuildXml (3) (3)

(After a succestul (After a succestul trytry to get a new to get a new documentBuilder documentBuilder builder builder fromfrom factory factory:):)

if (!docFile.exists()) { //create new docif (!docFile.exists()) { //create new doc document = builder.newDocument();document = builder.newDocument();

// add a comment:// add a comment: Comment comment =Comment comment =

document.document.createCommentcreateComment( ( "A simple personnel list");"A simple personnel list"); document.document.appendChildappendChild(comment);(comment);

// Create the root element:// Create the root element: root = document.root = document.createElementcreateElement("db");("db");

document.appendChild(root);document.appendChild(root);

Page 23: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 23

Code of Code of BuildXmlBuildXml (4) (4)

… … or if or if docFile docFile already exists:already exists:

} else { // access an existing doc} else { // access an existing doc try { // to parse docFiletry { // to parse docFile

document = builder.parse(docFile);document = builder.parse(docFile);root = document.root = document.getDocumentElementgetDocumentElement();();

} catch (SAXException se) {} catch (SAXException se) {System.err.println("Error: " + System.err.println("Error: " +

se.getMessage() );se.getMessage() );System.exit(1); System.exit(1);

} }

/* /* A similar A similar catch catch for a possiblefor a possible IOException */ IOException */

Page 24: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 24

Code of Code of BuildXmlBuildXml (5) (5)

Create and add two child elements to Create and add two child elements to rootroot::

Node personNode = Node personNode = createPersonNode(document, "1234", createPersonNode(document, "1234",

"Pekka", "Kilpeläinen");"Pekka", "Kilpeläinen");

root.root.appendChildappendChild(personNode);(personNode);

personNode = personNode = createPersonNode(document, "5678", createPersonNode(document, "5678",

"Irma", "Könönen");"Irma", "Könönen");

root.root.appendChildappendChild(personNode);(personNode);

Page 25: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 25

Code of Code of BuildXmlBuildXml (6) (6)

Finally, store the result document:Finally, store the result document:

try { // to write the try { // to write the // XML document to file fileName // XML document to file fileName

((XmlDocument) document).write( ((XmlDocument) document).write( new FileOutputStream(fileName)); new FileOutputStream(fileName));

} catch ( IOException ioe ) {} catch ( IOException ioe ) {

ioe.printStackTrace(); ioe.printStackTrace(); }}

Page 26: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 26

Subroutine to create Subroutine to create personperson elements elements

public Node createPersonNode(Document document, public Node createPersonNode(Document document,

String idNum, String fName, String lName) {String idNum, String fName, String lName) {

Element person = Element person = document.document.createElementcreateElement("person");("person");

person.person.setAttributesetAttribute("idnum", idNum);("idnum", idNum);

Element firstName = Element firstName = document.document.createElementcreateElement("first");("first");

person.person.appendChildappendChild(firstName);(firstName);

firstName.firstName.appendChildappendChild( ( document.document.createTextNodecreateTextNode(fName) );(fName) );

/* /* … similarly for a… similarly for a lastName */ lastName */

return person;return person;

} }

Page 27: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 27

The main routine for The main routine for BuildXmlBuildXml

public static void main(String args[]){ if public static void main(String args[]){ if (args.length > 0) {(args.length > 0) {

String fileName = args[0];String fileName = args[0];

BuildXml buildXml = new BuildXml buildXml = new BuildXml(fileName); BuildXml(fileName);

} else { } else {

System.err.println(System.err.println("Give filename as argument");"Give filename as argument");

};};

} // main} // main

Page 28: SDPLNotes 3.3: DOM Examples1 3.3 DOM Examples 1. DOM processing in a Web browser –a toy "XML database browser" –with JavaScript and MS Internet Explorer

SDPL Notes 3.3: DOM Examples 28

Summary of XML APIsSummary of XML APIs

XML processors make the structure and XML processors make the structure and contents of XML documents available to contents of XML documents available to applications through APIsapplications through APIs

Event-based APIsEvent-based APIs– notify application through parsing eventsnotify application through parsing events– e.g., the SAX callback interfacese.g., the SAX callback interfaces

Object-model (or tree) based APIsObject-model (or tree) based APIs– provide a full parse treeprovide a full parse tree– e.g, DOM, W3C Recommendatione.g, DOM, W3C Recommendation– more convenient, but may require too much more convenient, but may require too much

resources with the largest documentsresources with the largest documents Major parsers support both SAX and DOMMajor parsers support both SAX and DOM