XML DOM.

Slides:



Advertisements
Similar presentations
XML IV. The Document Object Model The Document Object model is a hierarchical structure of an XML document. It provides a means for accessing, and manipulating.
Advertisements

The Document Object Model
DOM. Document Object Model • Orginalt DOM for JavaScript – Manipulere dokumenter dynamisk i nettleser • Språknøytral API – OMG IDL • Standard for å –
XML CS What is XML?  XML: a "skeleton" for creating markup languages  you already know it!  syntax is identical to XHTML's: content  languages.
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Document Object Model. Lecture 18 The Document Object Model (DOM) is not a programming language It is an object-oriented model of web documents Each.
Document Object Model (DOM): An Abstract Data Structure for XML data Alex Dekhtyar Department of Computer Science University of Kentucky.
Document Object Model (DOM): An Abstract Data Structure for XML data Alex Dekhtyar Department of Computer Science CSC 560: Management of XML Data.
1 Processing XML with Java Representation and Management of Data on the Internet A comprehensive tutorial about XML processing with JavaXML processing.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
1 Processing XML with Java CS , Spring 2008/9.
Apache DOM Parser©zwzOctober 24, 2002 Wenzhong Zhao Department of Computer Science The University of Kentucky.
The Document Object Model and XML Chapter The Document Object Model: DOM.
XML files (with LINQ). Introduction to LINQ ( Language Integrated Query ) C#’s new LINQ capabilities allow you to write query expressions that retrieve.
CSE 154 LECTURE 24: XML AND JSON. Debugging responseXML in Firebug can examine the entire XML document, its node/tree structure.
XML C#.NET Software Development. eXtensible Markup Language Markup language that describes data Markup language that describes data Stores data as text.
1 XML Data Management 4. Domain Object Model Werner Nutt.
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
JS: Document Object Model (DOM)
5 Processing XML Parsing XML documents  Document Object Model (DOM)  Simple API for XML (SAX) Class generation Overview.
Stein XML 2.1 XML a first course Part 2 Yaakov J. Stein Chief Scientist RAD Data Communications.
JavaScript & DOM Client-side scripting. JavaScript JavaScript is a tool to automate client side (which is implemented using HTML so far) JavaSript syntax.
D2L Notes Be sure to submit your link in the dropbox provided on D2L You can just upload an empty text file if a file upload is required Do not use D2L.
Chapter 16 AJAX. Introduction AJAX stands for Asynchronous JavaScript And XML. AJAX is a type of programming made popular in 2005 by Google (with Google.
Parsing with DOM using MSXML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
DOM Robin Burke ECT 360. Outline XHTML in Schema JavaScript DOM (MSXML) Loading/Parsing Transforming parameter passing DOM operations extracting data.
Fall 2006 Florida Atlantic University Department of Computer Science & Engineering COP 4814 – Web Services Dr. Roy Levow Part 4 - XML.
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.
The XML Document Object Model (DOM) Aug’10 – Dec ’10.
5.2 DOM (Document Object Model). 2 Motto: To write it, it took three months; to conceive it three minutes; to collect the data in it — all my life. —F.
Web-based Programming Lanjut Pertemuan 9 Matakuliah: M0492 / Web-based Programming Lanjut Tahun: 2007.
WORKING WITH XML IN THE.NET FRAMEWORK. Accessing an XML File Basic activities: open it, read it.NET Framework provides structured and unstructured mechanisms.
JavaScript IV ECT 270 Robin Burke. Outline DOM JS document model review W3C DOM.
Navigating the DOM with ExtJS By Aaron Conran. Document Object Model The Document Object Model or DOM is a standard to represent HTML, XHTML and other.
C# and Windows Programming XML Processing. 2 Contents Markup XML DTDs XML Parsers DOM.
1 Dr Alexiei Dingli XML Technologies SAX and DOM.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
SDPLNotes 3.2: DOM1 3.2 Document Object Model (DOM) n How to provide uniform access to structured documents in diverse applications (parsers, browsers,
Introduction to the Document Object Model Eugenia Fernandez IUPUI.
Apache DOM Parser©zwzOctober 24, 2002 Wenzhong Zhao Department of Computer Science The University of Kentucky.
Markup basics. Markup languages add commentary to text files –so that the commentary can be ignored if not understood eg HyperText Markup Language –adds.
1 Javascript DOM Peter Atkinson. 2 Objectives Understand the nature and structure of the DOM Add and remove content from the page Access and change element.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
DOM (Document Object Model) - Parsing and Reading HTML and XML -
Advanced DOM Builds on last presentation on DOM Allows you to dynamically create elements and position them on a page DOM methods/properties are W3C standard.
Working with Elements and Attributes Using DOM Eugenia Fernandez IUPUI.
Document Object Model.  The XML DOM (Document Object Model) defines a standard way for accessing and manipulating XML documents.  The DOM presents an.
Create Element, Remove Child. The Document Tree Document Element Root Element Element Element Element Element Text: HelloWorld Attribute “href”
JS: Document Object Model (DOM) DOM stands for Document Object Model, and allows programmers generic access to: DOM stands for Document Object Model, and.
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:
DOM Dr. Reda Salama. Back to the HTML DOM Once we get a response back from the server, we probably want to update our HTML page The HTML page itself is.
Introduction to JavaScript DOM Instructor: Sergey Goldman.
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 CS What is XML?  XML: a "skeleton" for creating markup languages  you already know it!  syntax is identical to XHTML's: content  languages.
THE DOM.
Introduction to JavaScript DOM and Events
CHAPTER 5 DOCUMENT OBJECT MODEL
Scripting the DOM MIS 3502, Fall 2016 Jeremy Shafer Department of MIS
CGS 3066: Web Programming and Design Spring 2017
Introduction to the Document Object Model
DOM Robin Burke ECT 360.
CGS 3066: Web Programming and Design Spring 2016
Jim Fawcett CSE686 – Internet Programming Summer 2010
Geoffrey Fox and Bryan Carpenter PTLIU Laboratory for Community Grids
Week 11 Web site: XML DOM Week 11 Web site:
DOM Document Object Model.
DOM Document Object Model.
Processing XML.
XML DOM and CSS Instructors: Geoffrey Fox and Bryan Carpenter
Presentation transcript:

XML DOM

文件結構  整份文件 : document  文件之 root 元素 :  document.documentElement  文件為一個由節點組成的樹狀結構  節點 (node)  元素節點 (element)  屬性節點 (attribute)  文字節點 (text)

Node ( 節點 ) PropertyDescription childNodes Returns a NodeList of child nodes for a node parentNode Returns the parent node of a node firstChild Returns the first child of a node lastChild Returns the last child of a node nextSibling Returns the node immediately following a node previousSibling Returns the node immediately before a node nodeName Returns the name of a node, depending on its type nodeType Returns the type of a node nodeValue Sets or returns the value of a node, depending on its type ownerDocument Returns the root element (document object) for a node

Node Types Node typeDescriptionChildren Documentthe entire document (the root-node of the DOM tree) Element (max. one), Elementan elementElement, Text, CDATASection Attran attributeText textual content in an element or attributeNone CDATASectiona CDATA section in a document (text that will NOT be parsed) None Other node types: DocumentFragment, ProcessingInstruction, EntityReference, Comment, Entity, Notation

nodeType NodeTypeNamed Constant 1ELEMENT_NODE 2ATTRIBUTE_NODE 3TEXT_NODE 4CDATA_SECTION_NODE 5ENTITY_REFERENCE_NODE 6ENTITY_NODE 7PROCESSING_INSTRUCTION_NODE 8COMMENT_NODE 9DOCUMENT_NODE 10DOCUMENT_TYPE_NODE 11DOCUMENT_FRAGMENT_NODE 12NOTATION_NODE

<!-- var str=""; window.onload=function() { var ele=document.documentElement; showTree(ele); var w=window.open("", "tree", "width=500,height=800, scrollbars"); w.document.write(str); w.document.close(); } function showTree(node) { str += " "+node.nodeName+": "+node.nodeType; if (node.hasChildNodes()) { for (var i=0; i<node.childNodes.length;i++) showTree(node.childNodes[i]); } else str +=" "+node.nodeValue; str +=" "; } //-->

Node's methods MethodDescription appendChild() Adds a new child node to the end of the list of children of a node cloneNode() Clones a node hasChildNodes() Returns true if a node has any child nodes, otherwise it returns false insertBefore() Inserts a new child node before an existing child node removeChild() Removes a child node replaceChild() Replaces a child node

appendChild(), insertBefore() var img = new Image(); img.src="lily.jpg"; img.id ="lily1"; img.className="imgC1"; var div2=document.getElementById("div2"); div2.appendChild(img); div2.insertBefore(img, div2.firstChild);

Element Object Other properties: (the same as node) childNodes, firstChild, lastChild, nextSibling, nodeName, nodeType, nodeValue, ownerDocument, parentNode, previousSibling PropertyDescription attributes Returns a NamedNodeMap of attributes for the elementNamedNodeMap tagName Returns the name of the element

element's methods MethodDescription getAttribute() Returns the value of an attribute getAttributeNode() Returns an attribute node as an Attribute object getElementsByTagName() Returns a NodeList of matching element nodes, and their children hasAttribute() Returns whether an element has any attributes matching a specified name hasAttributes() Returns whether the element has any attributes removeAttribute() Removes a specified attribute removeAttributeNode() Removes a specified attribute node setAttribute() Adds a new attribute setAttributeNode() Adds a new attribute node Other methods: (the same as node) appendChild(), cloneNode(), hasChildNodes(), insertBefore(), removeChild(), replaceChild()

var img = document.createElement("img"); img.setAttribute("src", "lily.png"); img.setAttribute("id", "img2"); document.getElementById("div2").appendChild(img);

Attribute Object PropertyDescription name Returns the name of the attribute nodeName Returns the name of the node, depending on its type nodeType Returns the type of the node nodeValue Sets or returns the value of the node, depending on its type ownerDocume nt Returns the root element (document object) for an attribute specified Returns true if the attribute value is set in the document, and false if it's a default value in a DTD/Schema. value Sets or returns the value of the attribute

(XML) Document PropertyDescription asyncSpecifies whether downloading of an XML file should be handled asynchronously or not childNodesReturns a NodeList of child nodes for the document doctypeReturns the Document Type Declaration associated with the document documentElementReturns the root node of the document firstChildReturns the first child node of the document lastChildReturns the last child node of the document nodeNameReturns the name of a node (depending on its type) nodeTypeReturns the node type of a node nodeValueSets or returns the value of a node (depending on its type)

Document's methods MethodDescription createAttribute(name)Creates an attribute node with the specified name, and returns the new Attr object createCDATASection()Creates a CDATA section node createComment()Creates a comment node createElement()Creates an element node createTextNode()Creates a text node getElementById(id)Returns the element that has an ID attribute with the given value. If no such element exists, it returns null getElementsByTagName()Returns a NodeList of all elements with a specified name

var img = document.createElement("img"); var attrSrc = document.createAttribute("src"); attrSrc.nodeValue="lily1.jpg"; img.setAttributeNode(attrSrc); document.getElementById("content").appendChild(img);

getElementsByTagName()  getElementById() 只能用於 XHTML/HTML  在一般 XML document ,應使用 getElementsByTagName(" tagName ")  getElementsByTagName(" tagName ") 傳回一 個由 element 組成的陣列 (or collection)