xml7 - Document Object Model (DOM) Outline Introduction...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Document Object Model (DOM) Outline Introduction DOM Implementation DOM with JavaScript Setup DOM Components Creating Nodes Traversing the DOM Case Study: Modify the Day Planner Application to Use the DOM
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introduction XML Document Object Model (DOM) W3C standard recommendation Build tree structure in memory for XML documents DOM-based parsers parse these structures Exist in several languages (Java, C, C++, Python, Perl, etc.)
Background image of page 2
Introduction DOM tree Each node represents an element, attribute, etc. <?xml version = "1.0" ?> <message from = "Paul" to = "Tim" > <body> Hi, Tim! </body> </message> Node created for element message Element message has child node for body element Element body has child node for text " Hi, Tim! " Attributes from and to also have nodes in tree
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
DOM Implementations DOM-based parsers Microsoft’s msxml Sun Microsystem’s JAXP
Background image of page 4
Some DOM-based parsers.   Parser Description JAXP Sun Microsystem’s Java API for XML Parsing (JAXP) is available at no charge from java.sun.com/xml . XML4J IBM’s XML Parser for Java (XML4J) is available at no charge from www.alphaworks.ibm.com/tech/xml4j . Xerces Apache’s Xerces Java Parser is available at no charge from xml.apache.org/xerces . msxml Microsoft’s XML parser ( msxml ) version 2.0 is built-into Internet Explorer 5.5. Version 3.0 is also available at no charge from msdn.microsoft.com/xml . 4DOM 4DOM is a parser for the Python programming language and is available at no charge from fourthought.com/4Suite/4DOM . XML::DOM XML::DOM is a Perl module that we use in Chapter 17 to manipulate XML documents using Perl. For additional information, visit www- 4.ibm.com/software/developer/library/xm l-perl2 .
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
DOM and JavaScript We use JavaScript and msxml parser XML document marks up article Use DOM API to display document’s element names / values
Background image of page 6
Outline Fig. 8.2 Article  marked up with XML  tags.   1 <?xml version = "1.0" ?> 2 3 <!-- Fig. 8.2: article.xml --> 4 <!-- Article formatted with XML --> 5 6 <article> 7 8 <title> Simple XML </title> 9 10 <date> December 6, 2000 </date> 11 12 <author> 13 <fname> Tem </fname> 14 <lname> Nieto </lname> 15 </author> 16 17 <summary> XML is pretty easy. </summary> 18 19 <content> Once you have mastered HTML, XML is easily 20 learned. You must remember that XML is not for 21 displaying information but for managing information. 22 </content> 23 24 </article>
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Outline Fig. 8.3 Traversing  article.xml  with  JavaScript.   Element script allows for including scripting code Instantiate Microsoft XML DOM object Load article.xml into memory; msxml parses article.xml and stores it as tree structure 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 "http://www.w3.org/TR/html4/strict.dtd" > 3 4 <html> 5 6 <!-- Fig. 8.3 : DOMExample.html --> 7 <!-- DOM with JavaScript --> 8 9 <head> 10 <title> A DOM Example </title> 11 </head> 12 13 <body> 14 15 <script type = "text/javascript" language = 16 17 var xmlDocument = new ActiveXObject( "Microsoft.XMLDOM" ); 18 19 xmlDocument.load( "article.xml" ); 20 Element script allows for including scripting code Instantiate Microsoft XML DOM object Load article.xml into memory; msxml parses article.xml and stores it as tree structure
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 38

xml7 - Document Object Model (DOM) Outline Introduction...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online