Note 11 for XML

 

Watch & Read:

A very cool example of Javascript and HTML working together.

Javascript is an even driven quasi Object Oriented Language.

Objects, Methods, Properties and the ability to create functions

Files for Chapter 10 in the book are on my server in the XML directory

We will be using HTML DOM, XML DOM and JavaScript the next two weeks.

SAX & DOM provide a method for accessing and manipulating every object within an XML Document

Simple API for XML (Mini version of DOM)

SAX is similar to DOM except in the method of loading the XML object tree into memory. DOM loads the complete document and SAX loads the XML document one element at a time. (Better use of memory for large XML documents)

Document Object Model

W3schools said it best: The XML Document Object Model is a programming interface for XML documents.
The DOM defines the way an XML document can be accessed and manipulated.

DOM is an evolving API. Cover has a good background and explanation of DOM

An XML Parser uses DOM to break the XML document into an object Tree (based on the DOM core). The tree is loaded into the computer's memory so you can manipulate the objects using an object oriented language.

We will be using Microsoft XML Parser (built into IE 6)

Syntax for VB Script, Java Script and ASP:

Java Script: var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")

VBScript: set xmlDoc = CreateObject("Microsoft.XMLDOM")

Active Server Page (using VB Script): set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")

Example: Loading Schedule.XML into memory using Javascript:

<script type="text/javascript">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("schedule.xml")
document.write
("Show Me the node: ")

document.write
(xmlDoc.documentElement.childNodes.item(0).text)

<
/script>

Show me the Node

Try it with (xmlDoc.documentElement.nodeName) or (xmlDoc.documentElement.getAttribute("time"))

DOM & XPath will allow you to select nodes deep within your XML document: SelectSingleNode("Xpath") Example to manipulate the Title Element in schedule.xml: SelectSingleNode("/FallSchedule/Class/Title")

The W3Schools has several DOM Examples!

 

Review the following:

HTML DOM on W3schools

XML DOM on W3schools

JavaScript on W3schools

Terms you need to Lookup:

SAX, DOM, Javascript, method, properties, Object Oriented Programming

Homework:

Read: DOM at the W3schools Website

 

Final Step:

Review in your mind everything we covered in class and remember to cover it again before you go to bed so your mind to process this information while you sleep.