XML CS380 1. What is XML?  XML: a "skeleton" for creating markup languages  you already know it!  syntax is identical to XHTML's: content  languages.

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
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.
1 Extensible Markup Language: XML HTML: portable, widely supported protocol for describing how to format data XML: portable, widely supported protocol.
Document Object Model (DOM): An Abstract Data Structure for XML data Alex Dekhtyar Department of Computer Science University of Kentucky.
1 Extensible Markup Language: XML HTML: portable, widely supported protocol for describing how to format data XML: portable, widely supported protocol.
XML(EXtensible Markup Language). XML XML stands for EXtensible Markup Language. XML is a markup language much like HTML. XML was designed to describe.
CSE 154 LECTURE 23: XML. Storing structured data in arbitrary text formats (bad) My note: BEGIN FROM: Alice Smith TO: Robert Jones.
The Document Object Model (DOM) & Asynchronous Javascript And XML (AJAX) : an introduction UFCEKG-20-2 : Data, Schemas and Applications.
CSE 154 LECTURE 24: XML AND JSON. Debugging responseXML in Firebug can examine the entire XML document, its node/tree structure.
Pemrograman Berbasis WEB XML part 2 -Aurelio Rahmadian- Sumber: w3cschools.com.
XML introduction to Ahmed I. Deeb Dr. Anwar Mousa  presenter  instructor University Of Palestine-2009.
 Introduction to XML Introduction to XML  Features of XML Features of XML  Syntax of XML Syntax of XML  Syntax rules of XML document Syntax rules.
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)
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Pemrograman Berbasis WEB XML -Aurelio Rahmadian- Sumber: w3cschools.com.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
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.
Lecture 13 – XML and JSON SFDV3011 – Advanced Web Development Reference: 1.
Parsing with DOM using MSXML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
JavaScript – The DOM JavaScript is object based The browser is object based – We can access the browser's objects in the same way we did JavaScript's Two.
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.
How do I use HTML and XML to present information?.
XML eXtensible Markup Language. Topics  What is XML  An XML example  Why is XML important  XML introduction  XML applications  XML support CSEB.
WORKING WITH XML IN THE.NET FRAMEWORK. Accessing an XML File Basic activities: open it, read it.NET Framework provides structured and unstructured mechanisms.
CA Professional Web Site Development Class 2: Anatomy of a Web Site and Web Page & Intro to HTML.
1 Dr Alexiei Dingli XML Technologies XML. 2 XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry.
JavaScript IV ECT 270 Robin Burke. Outline DOM JS document model review W3C DOM.
WEB APPLICATION DEVELOPMENT For More visit:
Consuming eXtensible Markup Language (XML) feeds.
An Introduction to XML Sandeep Bhattaram
What it is and how it works
XML Introduction. Markup Language A markup language must specify What markup is allowed What markup is required How markup is to be distinguished from.
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.
Submitted To: Ms. Poonam Saini, Asst. Prof., NITTTR Submitted By: Rohit Handa ME (Modular) CSE 2011 Batch.
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 –
DTD ]>. Internal DTD Declaration ]> Faculty Director Reminder Please be regular in your classes.
IS444: Modern software development tools Dr. Azeddine Chikh.
Martin Kruliš by Martin Kruliš (v1.1)1.
DOM (Document Object Model) - Parsing and Reading HTML and XML -
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
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.
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.
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.
XML DOM Week 11 Web site:
XML Introduction to XML Extensible Markup Language.
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.
XML. What is XML? XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display data.
Extensible Markup Language (XML) Pat Morin COMP 2405.
XML intro. What is XML? XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display.
XML BASICS and more…. What is XML? In common:  XML is a standard, simple, self-describing way of encoding both text and data so that content can be processed.
CSE 154 LECTURE 13: XML AND JSON. Debugging responseXML in Firebug can examine the entire XML document, its node/tree structure.
THE DOM.
CSE 154 Lecture 12: XML.
>> JavaScript: Document Object Model
CSE 154 Lecture 12: XML.
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
CGS 3066: Web Programming and Design Spring 2016
XML in Web Technologies
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
DOM Document Object Model.
What is XML?.
Presentation transcript:

XML CS380 1

What is XML?  XML: a "skeleton" for creating markup languages  you already know it!  syntax is identical to XHTML's: content  languages written in XML specify:  names of tags in XHTML: h1, div, img, etc.  names of attributes in XHTML: id/class, src, href, etc.  rules about how they go together in XHTML: inline vs. block-level elements CS380 2

Why do we need XML?  to present complex data in human-readable form  "self-describing data" CS380 3

Anatomy of an XML file  begins with an header tag ("prolog")  has a single root element (in this case, note)  tag, attribute, and comment syntax is just like XHTML 4 Tove Jani Reminder Don't forget me this weekend! XML

Uses of XML  XML data comes from many sources on the web:  web servers store data as XML files  databases sometimes return query results as XML  web services use XML to communicate  XML is the de facto universal format for exchange of data  XML languages are used for music, math, vector graphics  popular use: RSS for news feeds & podcasts CS380 5

Pros and cons of XML pro:  easy to read (for humans and computers)  standard format makes automation easy  don't have to "reinvent the wheel" for storing new types of data  international, platform-independent, open/free standard  can represent almost any general kind of data (record, list, tree) CS380 6

Pros and cons of XML con:  bulky syntax/structure makes files large; can decrease performance example: quadratic formula in MathML  can be hard to "shoehorn" data into a good XML format CS380 7

What tags are legal in XML?  any tags you want!  examples:  an message might use tags called to, from, subject  a library might use tags called book, title, author  when designing an XML file, you choose the tags and attributes that best represent the data  rule of thumb: data = tag, metadata = attribute CS380 8

Doctypes and Schemas  "rule books" for individual flavors of XML  list which tags and attributes are valid in that language, and how they can be used together  used to validate XML files to make sure they follow the rules of that "flavor"  the W3C HTML validator uses the XHTML doctype to validate your HTML  for more info:  Document Type Definition (DTD) ("doctype")  W3C XML Schema CS380 9

XML and Ajax  web browsers can display XML files, but often you instead want to fetch one and analyze its data  the XML data is fetched, processed, and displayed using Ajax  (XML is the "X" in "Ajax")  It would be very clunky to examine a complex XML structure as just a giant string!  luckily, the browser can break apart (parse) XML data into a set of objects  there is an XML DOM, very similar to the (X)HTML DOM CS380 10

XML DOM tree structure  the XML tags have a tree structure  DOM nodes have parents, children, and siblings 11 children computers... XML

XML DOM tree structure 12

Recall: Javascript XML (XHTML) DOM The DOM properties and methods we already know can be used on XML nodes:  properties: firstChild, lastChild, childNodes, nextSibling, previousSibling, parentNode nodeName, nodeType, nodeValue, attributes  methods: appendChild, insertBefore, removeChild, replaceChild getElementsByTagName, getAttribute, hasAttributes, hasChildNodes  caution: cannot use HTML-specific properties like innerHTML in the XML DOM! 13

Navigating the node tree  caution: can only use standard DOM methods and properties in XML DOM  HTML DOM has Prototype methods, but XML DOM does not!  caution: can't use ids or classes to use to get specific nodes  id and class are not necessarily defined as attributes in the flavor of XML being read CS380 14

Navigating the node tree  caution: firstChild/nextSibling properties are unreliable  annoying whitespace text nodes!  the best way to walk the XML tree: var elms = node.getElementsByTagName("tagName")  returns an array of all node's children of the given tag name node.getAttribute("attributeName")  gets an attribute of an element CS380 15

Using XML data in a web page  Procedure: 1. use Ajax to fetch data 2. use DOM methods to examine XML: XMLnode.getElementsByTagName() 3. extract the data we need from the XML: XMLelement.getAttribute(), XMLelement.firstChild.nodeValue, etc. 4. create new HTML nodes and populate with extracted data: document.createElement(), HTMLelement.innerHTML 5. inject newly-created HTML nodes into page HTMLelement.appendChild() 16

Fetching XML using AJAX (template)  ajax.responseText contains the XML data in plain text  ajax.responseXML is a pre-parsed XML DOM object 17 new Ajax.Request( "url", { method: "get", onSuccess: functionName } );... function functionName(ajax) { do something with ajax.responseXML; } JS

Analyzing a fetched XML file using DOM We can use DOM properties and methods on ajax.responseXML: 18 // zeroth element of array of length 1 var foo = ajax.responseXML.getElementsByTagName("foo")[0]; // ditto var bar = foo.getElementsByTagName("bar")[0]; // array of length 2 var all_bazzes = foo.getElementsByTagName("baz"); // string "bleep" var bloop = foo.getAttribute("bloop"); JS XML

Recall: Pitfalls of the DOM We are reminded of some pitfalls of the DOM: CS XML // works - XML prolog is removed from document tree var foo = ajax.responseXML.firstChild; // WRONG - just a text node with whitespace! var bar = foo.firstChild; // works var first_baz = foo.getElementsByTagName("baz")[0]; // WRONG - just a text node with whitespace! var second_baz = first_baz.nextSibling; // works - why? var xyzzy = second_baz.firstChild; JS

CS Larger XML file example Everyday Italian Giada De Laurentiis XQuery Kick Start James McGovern Harry Potter J K. Rowling Learning XML Erik T. Ray XML

Navigating node tree example CS // make a paragraph for each book about computers var books = ajax.responseXML.getElementsByTagName("book"); for (var i = 0; i < books.length; i++) { var category = books[i].getAttribute("category"); if (category == "computers") { // extract data from XML var title = books[i].getElementsByTagName("title")[0].firstChil d.nodeValue; var author = books[i].getElementsByTagName("author")[0].firstChi ld.nodeValue; // make an XHTML tag containing data from XML var p = document.createElement("p"); p.innerHTML = title + ", by " + author; document.body.appendChild(p); } } JS