Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2003 Pearson Education, Inc. Slide 8-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide.

Similar presentations


Presentation on theme: "Copyright © 2003 Pearson Education, Inc. Slide 8-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide."— Presentation transcript:

1

2 Copyright © 2003 Pearson Education, Inc. Slide 8-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide to XML by Cheryl M. Hughes

3 Copyright © 2003 Pearson Education, Inc. Slide 8-2 CHAPTER 8 XML Programs and Programming

4 Copyright © 2003 Pearson Education, Inc. Slide 8-3 XML Programming Some applications for processing XML: Parsers Document Object Model (DOM) The Simple Application Programming Interface for XML (SAX) Programming languages (ie – Java) Databases

5 Copyright © 2003 Pearson Education, Inc. Slide 8-4 XML Parsers Two types of parsers: Validating – checks document against a document model Non-validating – only checks syntax Parsers are code libraries written in a programming language The XML parser that comes with Internet Explorer is called the MSXML parser

6 Copyright © 2003 Pearson Education, Inc. Slide 8-5 The Document Object Model (DOM) The first DOM specification was released by the W3C in October of 1998 Three levels of the recommendation: Level 1 - provides the core document models Level 2 - includes Level 1 and adds a model for style sheets, Level 3 - includes Level 1 and adds a model for content (DTD or schema) What DOM does: takes an XML document as input and creates an object structure in memory, which can then be accessed by programs DOM creates a tree-like structure, with branches and leaves to represent the hierarchy of the document

7 Copyright © 2003 Pearson Education, Inc. Slide 8-6 DOM Example – Microsofts XMLDOM XMLDOM is a COM component that is included with the Internet Explorer 5.0 The DOM creates an object in memory that can then be accessed by programs Some DOM object properties: childNodes firstChild lastChild Some DOM object methods: Load() CreateNode() Save()

8 Copyright © 2003 Pearson Education, Inc. Slide 8-7 DOM Example – XML file 1 2 3 Job Title: Web master 4 We are looking for a Web master to oversee the management 5 of our company Web site. The Web master will be responsible for 6working with other staff members to collect information for the 7Web site, and for creating and maintaining the Web 8pages. 9 10 Basic writing skills 11 good communication skills 12 HTML 13 14

9 Copyright © 2003 Pearson Education, Inc. Slide 8-8 DOM Example – HTML file with Javascript 1 2 3 Microsoft DOM Example Using Javascript 4 5 6/* This is a comment in JavaScript */ 7/* Create a new DOM object for our document */ 8var xmlDocument = new ActiveXObject("Microsoft.XMLDOM"); 9xmlDocument.async="false"; 10/* Use the "load" method to read our XML document into memory */ 11xmlDocument.load("job-posting.xml"); 12/* Print some HTML code */ 13document.write(" Using the Microsoft DOM "); 14/* BEGIN THE EXAMPLES */ 15/* 1. Prints the value of the first child node */ 16document.write(" 1. firstChild is: "); 17document.write(xmlDocument.documentElement.firstChild.text); 18document.write(" ");

10 Copyright © 2003 Pearson Education, Inc. Slide 8-9 DOM Example – HTML file with Javascript (cont.) 19/* 2. Prints the value of the last child node */ 20document.write(" 2. lastChild is: "); 21document.write(xmlDocument.documentElement.lastChild.text); 22document.write(" "); 23/* 3. Prints the name of the lastChild element */ 24document.write(" 3. lastChild node name is: "); 25document.write(xmlDocument.documentElement.lastChild.nodeName); 26document.write(" "); 27/* 4. Prints the name of the child node stored in item(1) */ 28/* Then, it checks to see if the node has child elements */ 29document.write(" 4. item(2) is: "); 30document.write(xmlDocument.documentElement.childNodes.item(2).nodeName); 31document.write(" Does this node have child elements? "); 32document.write (xmlDocument.documentElement.childNodes.item(2).hasChildNodes()); 33document.write(" "); 34/* End the examples */ 35 36 37

11 Copyright © 2003 Pearson Education, Inc. Slide 8-10 The Simple Application Programming Interface for XML (SAX) The SAX 1.0 recommendation was released by the W3C in May 1998 SAX is an event-based API that reads the document in a serial fashion Sax is much faster than DOM, and does not store information in memory

12 Copyright © 2003 Pearson Education, Inc. Slide 8-11 SAX Example XML File: The Web Wizards Guide to XML C. Hughes SAX processor events: 1 Start document 2 Start element (book) 3 Attribute (id=1234) 4 Start element (title) 5 Text (The Web Wizards Guide to XML) 6 End element (title) 7 Start element (author) 8 Text (C. Hughes) 9 End element (author) 10 End element (book) 11 End document

13 Copyright © 2003 Pearson Education, Inc. Slide 8-12 Comparing SAX and DOM When to use SAX: Processing large documents Searching Stopping the program When to use DOM: Accessing cross-referenced data Modifying the XML document Creating new XML documents

14 Copyright © 2003 Pearson Education, Inc. Slide 8-13 XML and Programming Languages XML has become popular with object- oriented programming languages DOM created objects that can be easily accessed Some popular languages that are embracing XML: Java Perl C++

15 Copyright © 2003 Pearson Education, Inc. Slide 8-14 XML and Databases XMLs structure makes it a good technology for storing data XML can support relationships among pieces of data that relational databases can not XML Query Language (XQuery) – being developed as a standardized query language that will span all types of XML documents and data sources

16 Copyright © 2003 Pearson Education, Inc. Slide 8-15 Examples of XML Programs Distributed Authoring and Versioning on the World Wide Web (WebDAV) Wireless Application Protocol (WAP) Scalable Vector Graphics (SVG) Open Financial Exchange (OFX) Mathematical Markup Language (MathML) Chemical Markup Language (CML) Extensible Hypertext Markup Language (XHTML) Resource Description Framework (RDF)

17 Copyright © 2003 Pearson Education, Inc. Slide 8-16 MathML Examples Equation: 3+5 1 2 3 3 + 4 5 5 Equation: ab 1 2 x 3 ⁢ 4 b 5


Download ppt "Copyright © 2003 Pearson Education, Inc. Slide 8-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide."

Similar presentations


Ads by Google