XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.

Slides:



Advertisements
Similar presentations
CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT.
Advertisements

1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
Tutorial 16 Working with Dynamic Content and Styles.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
AJAX & By – Anupama Sharma. Defining Ajax Ajax isn’t a technology. It’s really several technologies, each flourishing in its own right, coming together.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
XP New Perspectives on Microsoft Access 2002 Tutorial 71 Microsoft Access 2002 Tutorial 7 – Integrating Access With the Web and With Other Programs.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
INTRODUCTION TO CLIENT-SIDE WEB PROGRAMMING ACM 511 ACM 262 Course Notes.
WORKING WITH NAMESPACES
The Document Object Model (DOM) & Asynchronous Javascript And XML (AJAX) : an introduction UFCEKG-20-2 : Data, Schemas and Applications.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
4.1 JavaScript Introduction
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
Creating an Animated Web Page
Working with Objects Creating a Dynamic Web Page.
CITS1231 Web Technologies JavaScript and Document Object Model.
XP Tutorial 4 New Perspectives on JavaScript, Comprehensive1 Working with Objects Creating an Animated Web Page.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Introduction to Applets CS 3505 Client Side Scripting with applets.
Working with the XML Document Object Model ©NIITeXtensible Markup Language/Lesson 7/Slide 1 of 44 Objectives In this lesson, you will learn to: *Identify.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 34 - Case Study: Active Server Pages and XML Outline 34.1 Introduction 34.2 Setup and Message.
Client side web programming Introduction Jaana Holvikivi, DSc. School of ICT.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Scripting with the DOM Ellen Pearlman Eileen Mullin Programming the Web.
DHTML: Working with Objects Creating a Dynamic Web Page.
XP 1 New Perspectives on XML Binding XML Data with Internet Explorer.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
XP New Perspectives on XML, 2nd Edition Tutorial 2 1 TUTORIAL 2 WORKING WITH NAMESPACES.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
XP Tutorial 16 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Dynamic Content and Styles Creating a Dynamic Table of Contents.
1 Overview of XSL. 2 Outline We will use Roger Costello’s tutorial The purpose of this presentation is  To give a quick overview of XSL  To describe.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
XSLT. XSLT stands for Extensible Stylesheet Language Transformations XSLT is used to transform XML documents into other kinds of documents. XSLT can produce.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Accessing XML Documents Using DOM ©NIITeXtensible Markup Language/Lesson 8/Slide 1 of 23 Objectives In this lesson, you will learn to: * Use XML DOM objects.
XP Tutorial 5 New Perspectives on JavaScript, Comprehensive1 Working with Special Effects Creating Rollovers, Menus, Filters, and Transitions.
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
AJAX – Asynchronous JavaScript And XML By Kranthi Kiran Nuthi CIS 764 Kansas State University.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
XML DOM Week 11 Web site:
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
XML Schema – XSLT Week 8 Web site:
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Apache Cocoon – XML Publishing Framework 데이터베이스 연구실 박사 1 학기 이 세영.
XP Tutorial 10 New Perspectives on JavaScript, Comprehensive 1 Working with Dynamic Content and Styles Creating a Dynamic Table of Contents.
I Copyright © 2004, Oracle. All rights reserved. Introduction.
Session IV Chapter 14 – Chapter 14 – XSLThttp://
DHTML.
Programming Web Pages with JavaScript
Unit 4 Representing Web Data: XML
XML in Web Technologies
Chapter 7 Representing Web Data: XML
Week 11 Web site: XML DOM Week 11 Web site:
Presentation transcript:

XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10

XP Updating XML documents New Perspectives on XML, 2 nd Edition Tutorial 10 2

XP XML API XML and XSLT are a markup languages –Describe how things are arranged and how things look API –Collection of prewritten procedures –Enables processing of XML Two APIs for use with XML –W3C DOM (Document Object Model) Requires entire XML document be held in memory; memory intensive –SAX (Simple API for XML) Can be used on a stream of XML which need not be held entirely in memory Developed by XML-DEV mailing list New Perspectives on XML, 2 nd Edition Tutorial 10 3

XP New Perspectives on XML, 2 nd Edition Tutorial 10 4 DOM LEVELS Page 572

XP General approach 1.Determine which browser is being used 2.Create document object 3.Load a file into the document object 4.Transform the document object using XSLT 5.Display the transformed document New Perspectives on XML, 2 nd Edition Tutorial 10 5

XP New Perspectives on XML, 2 nd Edition Tutorial 10 6 CREATING A CROSS-BROWSER SOLUTION Because there are some fundamental differences between Internet Explorer and the Mozilla-based browsers in implementing the Document Object Model, any program code that you write has to first determine which browser is in use. –Object-detection var IE = window.ActiveXObject ? true:false; var MOZ = document.implementation.createDocument ? true:false; Java Script is case sensitive

XP New Perspectives on XML, 2 nd Edition Tutorial 10 7 CREATING A CROSS-BROWSER SOLUTION if (IE) { Internet Explorer code } else if (MOZ) { Mozilla code }

XP General approach 1.Determine which browser is being used 2.Create document object 3.Load a file into the document object 4.Transform the document object using XSLT 5.Display the transformed document New Perspectives on XML, 2 nd Edition Tutorial 10 8

XP New Perspectives on XML, 2 nd Edition Tutorial 10 9 CREATING A DOCUMENT OBJECT IN INTERNET EXPLORER A document object is an object that can store the contents and structure of a document. docObj = new ActiveXObject(PID); –docObj is the variable name of the document object – PID is the program ID that indicates the type of document object to be created. Each version of MSXML supports a different program ID

XP CREATING A DOCUMENT OBJECT IN INTERNET EXPLORER IE creates document objects using ActiveX –Microsoft technology used to create interactive content for the web Program IDs supported by different versions of MSXML Msxml2.DOMDocument.5.0 Msxml2.DOMDocument.4.0 Msxml2.DOMDocument.3.0 MSXML2.DOMDocument Microsoft.XMLDOM Example: XMLdoc = new ActiveXobject (“Msxml2.DOMDocument.3.0”); New Perspectives on XML, 2 nd Edition Tutorial To determine the most recent version, query the browser (page 576)

XP New Perspectives on XML, 2 nd Edition Tutorial CREATING A DOCUMENT OBJECT IN MOZILLA Syntax docObj = document.implementation.createDocument (uri,root,doctype); uri is the URI of the document’s namespace root is the qualified name of the document’s root element doctype is the type of document to create (always enter a value of null) Example XMLdoc = document.implementaton.createDocument (“ Persons, null);

XP General approach 1.Determine which browser is being used 2.Create document object 3.Load a file into the document object 4.Transform the document object using XSLT 5.Display the transformed document New Perspectives on XML, 2 nd Edition Tutorial 10 12

XP New Perspectives on XML, 2 nd Edition Tutorial LOADING A FILE INTO A DOCUMENT OBJECT First choose load strategy: –An asynchronous load does not require the application loading the file to wait for it to finish loading before proceeding through the lines in the program code –A synchronous load causes the application to stop until the file is completely loaded. Example: choose synchronous load docObj.async=false; Example load: docObj.load(url) Default Use for large files or retrieving files through a slow internet connection

XP General approach 1.Determine which browser is being used 2.Create document object 3.Load a file into the document object 4.Transform the document object using XSLT 5.Display the transformed document New Perspectives on XML, 2 nd Edition Tutorial 10 14

XP New Perspectives on XML, 2 nd Edition Tutorial Transforming a Document Using XSLT (Internet Explorer) Because XSLT style sheets are also XML documents, you need to create a document object using ActiveX for the style sheet –Rental-threaded model Content is accessed by the XML processor using a single sequence of instructions –Free-threaded model Content is access by the processor through multiple input threads Preferable for efficiency reasons

XP New Perspectives on XML, 2 nd Edition Tutorial Transforming a Document Using XSLT (Internet Explorer) Once a style sheet is loaded, IE applies the style sheet to the source document using either of two methods: –transformNode() Creates a text string containing the code for the result document –transformNotetoObject() Stores the result lin another document object Either method can be drag on resources –Create a template Object and Processor Object… Simple Can write code to further manipulate the contents

XP New Perspectives on XML, 2 nd Edition Tutorial Template and Processor Objects (Internet Explorer) Template object –Uses a large and complicated style sheet or for programs that need to run several transformations, –Increases the efficiency of the program because the cached style sheet can be accessed repeatedly without being recompiled Processor object –Processes the template object to produce the result object Display the result object

XP Creating a Template Object (Internet Explorer) Processor must compile the style sheet object each time the transformation is run. For large and complicated style sheets or programs that need to run several transformations, store the style sheet in a template object and use the free-threaded model Store the program IDs in an array: Var FreeThreadPID = [“Msxm1.FreeThreadedDocument.5.0”, “Msxm1.FreeThreadedDocument.4.0”, “Msxm1.FreeThreadedDocument.3.0”]; Create document object for the style sheet XSLTdoc=New Active Xobject (getPID (FreeThreadPID) ); New Perspectives on XML, 2 nd Edition Tutorial 10 18

XP Using a processor object (Internet Explorer) Steps for creating and using a processor object 1.Insert a free-threaded style sheet into the template object 2.Create an XSLT processor based on the template 3.Specify an input source document for the processor 4.Transform the source document based on the style sheet Example function doTransform() { var contTable = document.getElementById(“ctabale”)” If (IE) { XSLTemp.stylesheet=XSLTdoc: XSLTProc=XSLTemp.createprocessor(); XSLTProc.input=XMLdoc; XSLTLProc.transform()XSLTproc.out; } See pages for details New Perspectives on XML, 2 nd Edition Tutorial 10 19

XP New Perspectives on XML, 2 nd Edition Tutorial TRANSFORMING A DOCUMENT WITH MOZILLA

XP New Perspectives on XML, 2 nd Edition Tutorial TRANSFORMING A DOCUMENT WITH MOZILLA Figure page 589

XP New Perspectives on XML, 2 nd Edition Tutorial CONVERTING A DOCUMENT OBJECT OR FRAGMENT TO A TEXT STRING WITH MOZILLA To convert a document object or a fragment to a text string in Mozilla, you create a serializer object, which contains a textual representation of the contents of a document object or fragment serialObj = new XMLSerializer(); Where serialObj is the serializer object that will contain the text of the document object or fragment.

XP New Perspectives on XML, 2 nd Edition Tutorial CONVERTING A DOCUMENT OBJECT OR FRAGMENT TO A TEXT STRING WITH MOZILLA Figure Page 591

XP General approach 1.Determine which browser is being used 2.Create document object 3.Load a file into the document object 4.Transform the document object using XSLT 5.Display the transformed document New Perspectives on XML, 2 nd Edition Tutorial 10 24

XP Display the document: New Perspectives on XML, 2 nd Edition Tutorial 10 25

XP New Perspectives on XML, 2 nd Edition Tutorial WORKING WITH THE DOCUMENT OBJECT Page 592

XP New Perspectives on XML, 2 nd Edition Tutorial WORKING WITH THE DOCUMENT OBJECT Page 593

XP New Perspectives on XML, 2 nd Edition Tutorial VIEWING THE NODE TREE A node that contains other nodes is a parent node, and the nodes it contains are child nodes. Nodes that share the same parent are sibling nodes. Nodes can contain different types of content. For example, element nodes refer to elements from the Document Object Model, and text nodes refer to the actual text content of element nodes. Attribute nodes refer to the attributes contained within elements or processing instructions.

XP New Perspectives on XML, 2 nd Edition Tutorial ACCESSING ELEMENTS BY TAG NAME docObj.getElementsByTagName(tag) Where docObj is the document object and tag is the element’s tag name. Example: XMLdoc.getElementsByTagName("person")

XP New Perspectives on XML, 2 nd Edition Tutorial USING FAMILIAL RELATIONS Each node in a node tree can also be treated as a node object with its own collection of properties and methods nodeObj.firstChild Where nodeObj is a node from the document’s node tree.

XP New Perspectives on XML, 2 nd Edition Tutorial USING FAMILIAL RELATIONS Page 595

XP New Perspectives on XML, 2 nd Edition Tutorial NODE TYPES, NAMES, AND VALUES nodeObj.nodeType nodeObj.nodeName nodeObj.nodeValue Page 596

XP New Perspectives on XML, 2 nd Edition Tutorial ADDING AND REMOVING NODES nodeObj = docObj.createElement(tag); Where –nodeObj is the new element node –docObj is the document object containing the new node –tag is the tag name associated with the element

XP New Perspectives on XML, 2 nd Edition Tutorial CREATING NODE OBJECTS Page 599

XP New Perspectives on XML, 2 nd Edition Tutorial INSERTING AND REMOVING NODES Page 600

XP New Perspectives on XML, 2 nd Edition Tutorial CREATING A DOCUMENT FRAGMENT Page 601

XP New Perspectives on XML, 2 nd Edition Tutorial CLONING A DOCUMENT FRAGMENT Page 602

XP Add new Records to the Contribution List New Perspectives on XML, 2 nd Edition Tutorial 10 38

XP New Perspectives on XML, 2 nd Edition Tutorial ATTRIBUTE METHODS Page 609

XP New Perspectives on XML, 2 nd Edition Tutorial FILTERING THE SOURCE DOCUMENT 100]" /> Page 614

XP FILTERING THE SOURCE DOCUMENT function filterList() { var filterStr = document.webform.filter.value; if (filterStr==“”) filter=“//person” else filter = “//person[“+filterStr+”]”; } New Perspectives on XML, 2 nd Edition Tutorial Extract filter expression from form Insert filter expression into parameter

XP New Perspectives on XML, 2 nd Edition Tutorial SETTING A PARAMETER VALUE in Internet Explorer processorObj.addParameter(parameter, value, uri) processorObj is a processor object parameter is the name of the style sheet parameter value is the value passed to the parameter uri is an optional value that specifies the namespace URI for the parameter

XP New Perspectives on XML, 2 nd Edition Tutorial SELECTING A NODE SET in Internet Explorer object.selectSingleNode(xpath) Where object is a document or node object and xpath is an XPath expression. object.selectNodes(xpath)

XP New Perspectives on XML, 2 nd Edition Tutorial SAVING AN XML DOCUMENT docObj.save(location) Where location is one of the following: –A filename –The name of another document object –An ASP (Active Server Pages) response object –A custom COM object that supports persistence Supported on IE on a Web server.

XP New Perspectives on XML, 2 nd Edition Tutorial WORKING WITH AJAX AJAX, or Asynchronous JavaScript and XML, refers to the use of HTML, XML, XSLT, and JavaScript to enable fast, efficient communication between applications running on a user’s browser and data stored and updated on a secure Web server. In the classic Web application model, a user interacts with a Web server through a Web page running on their browser.

XP New Perspectives on XML, 2 nd Edition Tutorial WORKING WITH AJAX The AJAX Web application model adds an intermediary between the user and the server-side system, which is called an AJAX engine. The AJAX engine is responsible for communicating with the server and for relaying any information from the server to the user interface.

XP New Perspectives on XML, 2 nd Edition Tutorial WORKING WITH AJAX Ajax engine: Written in JavaScript Ajax uses HTTP to communicate with Web server Client uses JavaScript call functions to communicate with Ajax engine Ajax engine placed within Web page Enables asynchronous rather than synchronous communication

XP New Perspectives on XML, 2 nd Edition Tutorial WORKING WITH AJAX Page 628

XP New Perspectives on XML, 2 nd Edition Tutorial THE XMLHttpRequest OBJECT Internet Explorer –To create an XMLHttpRequest object, use reqObj = new ActiveXObject(progID); Where reqObj is the XMLHttpRequest object and progID is an ActiveX program ID for XMLHttpRequest objects. Mozilla and Safari –To create an XMLHttpRequest object, use reqObj = new XMLHttpRequest(); Ajax engine

XP New Perspectives on XML, 2 nd Edition Tutorial METHODS OF THE XMLHttpRequest OBJECT Page 630

XP New Perspectives on XML, 2 nd Edition Tutorial PROPERTIES OF THE XMLHttpRequest OBJECT Page 631