XML 6.4 DOM 6. The XML ‘Alphabet Soup’ XMLExtensible Markup Language Defines XML documents XSLExtensible Stylesheet Language Language for expressing stylesheets;

Slides:



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

The Document Object Model
1/7 ITApplications XML Module Session 8: Introduction to Programming with XML.
14-Jun-15 DOM. SAX and DOM SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files DOM is a W3C standard SAX is an ad-hoc.
©Silberschatz, Korth and Sudarshan10.1Database System Concepts W3C Activities HTML: is the lingua franca for publishing on the Web XHTML: an XML application.
Java API for XML Processing (JAXP) CSE 4/586: Distributed Systems Department of Computer Science and Engineering University at Buffalo, New York Jia Zhao.
XML Introduction By Hongming Yu Feb 6 th, Index Markup Language: SGML, HTML, XML An XML example Why is XML important XML introduction XML applications.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
By: Shawn Li. OUTLINE XML Definition HTML vs. XML Advantage of XML Facts Utilization SAX Definition DOM Definition History Comparison between SAX and.
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.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
Introduction to XML cs3505. References –I got most of this presentation from this site –O’reilly tutorials.
1 XML at a neighborhood university near you Innovation 2005 September 16, 2005 Kwok-Bun Yue University of Houston-Clear Lake.
XML and its applications: 4. Processing XML using PHP.
XML eXtensible Markup Language w3c standard Why? Store and transport data Easy data exchange Create more languages WSDL (Web Service Description Language)
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.
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
XML Overview. Chapter 8 © 2011 Pearson Education 2 Extensible Markup Language (XML) A text-based markup language (like HTML) A text-based markup language.
CIS 375—Web App Dev II DOM. 2 Introduction to DOM The XML Document ________ Model (DOM) is a programming interface for XML documents. It defines the way.
Advanced Java Session 9 New York University School of Continuing and Professional Studies.
XML Parsers Overview  Types of parsers  Using XML parsers  SAX  DOM  DOM versus SAX  Products  Conclusion.
Parsing with DOM using MSXML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML TUTORIAL Portions from w3 schools By Dr. John Abraham.
Electronic Commerce COMP3210 Session 4: Designing, Building and Evaluating e-Commerce Initiatives – Part II Dr. Paul Walcott Department of Computer Science,
DOM Robin Burke ECT 360. Outline XHTML in Schema JavaScript DOM (MSXML) Loading/Parsing Transforming parameter passing DOM operations extracting data.
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.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
XML Document Object Model Anthony Borquez. The Document Object Model a programming interface for HTML and XML documents. It defines the way a document.
WEB BASED DATA TRANSFORMATION USING XML, JAVA Group members: Darius Balarashti & Matt Smith.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Scripting with the DOM Ellen Pearlman Eileen Mullin Programming the Web.
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.
1 Dr Alexiei Dingli XML Technologies SAX and DOM.
XML Study-Session: Part III
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
CS 157B: Database Management Systems II February 11 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
SAX2 and DOM2 Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
Web Technologies Lecture 4 XML and XHTML. XML Extensible Markup Language Set of rules for encoding a document in a format readable – By humans, and –
When we create.rtf document apart from saving the actual info the tool saves additional info like start of a paragraph, bold, size of the font.. Etc. This.
XML Parser using JavaScript. 2 Microsoft To manipulate an XML document in javascript, you need an XML parser. Today all browsers come with in-built parsers.
 defined as Extensible Markup Language (XML) is a set of rules for encoding documents  Defines structure and data.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
Computing & Information Sciences Kansas State University Friday, 20 Oct 2006CIS 560: Database System Concepts Lecture 24 of 42 Friday, 20 October 2006.
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.
©Silberschatz, Korth and Sudarshan10.1Database System Concepts W3C - The World Wide Web Consortium W3C - The World Wide Web Consortium.
Martin Kruliš by Martin Kruliš (v1.1)1.
Document Object Model.  The XML DOM (Document Object Model) defines a standard way for accessing and manipulating XML documents.  The DOM presents an.
7-Mar-16 Simple API XML.  SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files  DOM is a W3C standard  SAX is an.
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
USING ANDROID WITH THE DOM. Slide 2 Lecture Summary DOM concepts SAX vs DOM parsers Parsing HTTP results The Android DOM implementation.
XML DOM Week 11 Web site:
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
21-Jun-16 Document Object Model DOM. SAX and DOM SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files DOM is a W3C.
XML. Contents  Parsing an XML Document  Validating XML Documents.
THE DOM.
DHTML.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
In this session, you will learn to:
Unit 4 Representing Web Data: XML
XML Related Technologies
DOM Robin Burke ECT 360.
XML in Web Technologies
Database Processing with XML
Week 11 Web site: XML DOM Week 11 Web site:
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
In this session, you will learn to:
Introduction to Programming the WWW I
XML Introduction By Hongming Yu Feb 6th, 2002.
DOM 24-Feb-19.
Presentation transcript:

XML 6.4 DOM 6

The XML ‘Alphabet Soup’ XMLExtensible Markup Language Defines XML documents XSLExtensible Stylesheet Language Language for expressing stylesheets; consists of XSLT and XSL-FO XSLTXSL TransformationsLanguage for transforming XML documents XSL-FOXSL Formatting ObjectsLanguage to describe precise layout of text on a page Data Island XML data embedded in a HTML page Data Binding Automatic population of HTML elements from XML data Namespace A collection of names, identified by a URI reference, which are used in XML documents

The XML ‘Alphabet Soup’ DTDDocument Type DefinitionNon-XML schema DOMDocument Object ModelAPI to read, create and edit XML documents; creates in-memory object model SAXSimple API for XMLAPI to parse XML documents; event-driven XML Schema (XSD) XML Schema Definitionan XML based alternative to DTD XPathXML Path LanguageA language for addressing parts of an XML document, designed to be used by both XSLT and XPointer XPointerXML Pointer LanguageSupports addressing into the internal structures of XML documents XLinkXML Linking LanguageDescribes links between XML documents XQueryXML Query Language (draft) Flexible mechanism for querying XML data as if it were a database

The XML ‘Alphabet Soup’ SOAP Simple Object Access Protocol A simple XML based protocol to let applications exchange information over HTTP WSDL Web Services Description Language An XML-based language for describing Web services and how to access them WAP Wireless Application Protocol The leading standard for information services on wireless terminals like digital mobile phones WML Wireless Markup Language WAP uses the mark-up language WML (not HTML)

SAX and DOM SAX and DOM are standards for XML parsers - program APIs to read and interpret XML files  DOM is a W3C standard  SAX is an ad-hoc (but very popular) standard There are various implementations available Java implementations are provided in JAXP (Java API for XML Processing) JAXP is included as a package in Java 1.4  JAXP is available separately for Java 1.3 Unlike many XML technologies, SAX and DOM are relatively easy

Difference between SAX and DOM DOM reads the entire XML document into memory and stores it as a tree data structure SAX reads the XML document and sends an event for each element that it encounters Consequences:  DOM provides “random access” into the XML document  SAX provides only sequential access to the XML document  DOM is slow and requires huge amounts of memory, so it cannot be used for large XML documents  SAX is fast and requires very little memory, so it can be used for huge documents (or large numbers of documents)  This makes SAX much more popular for web sites  Some DOM implementations have methods for changing the XML document in memory; SAX implementations do not

SAX Callbacks SAX works through callbacks: you call the parser, it calls methods that you supply Your program main(...) startDocument(...) startElement(...) characters(...) endElement( ) endDocument( ) parse(...) The SAX parser

What is the DOM? The Document Object Model (DOM) provides a standard programming interface to a wide variety of applications. The XML DOM is designed to be used with any programming language and any operating system.  It is fully described in the W3C DOM specification  With the XML DOM, a programmer can create an XML document, navigate its structure, and add, modify, or delete its elements DOM provides generic access to DOM-compliant documents: add, edit, delete, manipulate DOM is language-independent The DOM is based on a tree view of your document. Nodes! Nodes! Nodes! DOM useful for CSS, HTML, XML DOM + client-side scripting + HTML = DHTML

DOM components Document top-level view of the document, with access to all nodes (including root element)  createElement method - creates an element node  createAttribute method - creates an attribute node  createComment method - creates a comment node  getDocumentElement method - returns root element  appendChild method - appends a child node  getChildNodes method - returns child nodes

DOM components II Node represents a node - "A node is a reference to an element, its attributes, or text from the document."  cloneNode method - duplicates a node  getNodeName method - returns the node name  getNodeName method - returns the node's name  getNodeType method - returns the node's type  getNodeValue method - returns the node's value  getParentNode method - returns the node's parent's name  hasChildNodes method - true if has child nodes  insertBefore method - stuffs child in before specified child  removeChild method - removes the child node  replaceChild method - replaces one child with another  setNodeValue method - sets node's value

DOM components III attribute represents an attribute node -  getAttribute method - gets attribute!  getTagName method - gets element's name  removeAttribute method - deletes it  setAttribute method - sets att's value

Parsing the DOM To read and update - create and manipulate - an XML document, you need an XML parser. The Microsoft XMLDOM parser features a programming model that:  Supports JavaScript, VBScript, Perl, VB, Java, C++ and more  A COM component that comes with Microsoft Internet Explorer 5.0  Supports W3C XML 1.0 and XML DOM  Supports DTD and validation

Creating an XML document object JavaScript:  var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") VBScript:  set xmlDoc = CreateObject("Microsoft.XMLDOM").asp:  set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")

Adding in a new element var link = document.createElement('a'); link.setAttribute('href', 'mypage.htm');

locating a slot in the document by location:  document.childNodes[1].childNodes[0]  Find the main document element (HTML), and find its second child (BODY), then look for its first child (DIV) by ID:  document.getElementById('myDiv').appendChild(txt);

Hiding an element document.childNodes[1].childNodes[1].childNodes[0].style.display = "none";

Loading an XML document object into the parser var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load(“note.xml") // processing the document goes here

Manually loading XML into the parser // load up variable var with some xml var text=" " text=text+" John Robert " text=text+" Reminder " text=text+" Don't forget your homework! " text=text+" " // now create the DO var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.loadXML(text) // process the document

parseError object document.write(xmlDoc.parseError.property)  errorCode : Returns a long integer error code  reason : Returns a string explaining the reason for the error  line : Returns a long integer representing the line number for the error  linePos : Returns a long integer representing the line position for the error  srcText : Returns a string containing the line that caused the error  url : Returns the url pointing the loaded document  filePos : Returns a long integer file position of the error

Traversing nodes set xmlDoc=CreateObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("note.xml") for each x in xmlDoc.documentElement.childNodes document.write(x.nodename) document.write(": ") document.write(x.text) next

Calling XML nodes by name var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("note.xml") document.write(xmlDoc.getElementsByTagName("from").item(0).text)

References W3School DOM Tutorial  MSXML 4.0 SDK

Reading List W3School DOM Tutorial 