Web Client Side Technologies Raneem Qaddoura

Slides:



Advertisements
Similar presentations
Copyright © Steven W. Johnson
Advertisements

JSON IDU0075 Sissejuhatus veebiteenustesse.  JSON stands for JavaScript Object Notation  JSON is lightweight text-data interchange format  JSON is.
15-Jul-15 JSON. JSON example “JSON” stands for “JavaScript Object Notation” Despite the name, JSON is a (mostly) language-independent way of specifying.
Chris Pinski.  History  What is Ajax  Who uses Ajax  Underlying Technologies  SE Aspect  Common Problems  Conclusion.
AJAX and Java ISYS 350. AJAX Asynchronous JavaScript and XML: – Related technologies: JavaScript, Document Object Model, XML, server-side script such.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
RESTful applications Norman White. REST Representational state transfer Key concepts – Client Server architecture built on transferring resources between.
Lecture 13 – XML and JSON SFDV3011 – Advanced Web Development Reference: 1.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
Creating Dynamic Webpages
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 –
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
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 AJAX Asynchronous JavaScript and XML --- MADHAVI
OVERVIEW AND PARSING JSON. What is JSON JavaScript Object Notation Used to format data Commonly used in Web as a vehicle to describe data being sent between.
AJAX – Asynchronous JavaScript And XML By Kranthi Kiran Nuthi CIS 764 Kansas State University.
Google maps engine and language presentation Ibrahim Motala.
JSON. JSON as an XML Alternative JSON is a light-weight alternative to XML for data- interchange JSON = JavaScript Object Notation It’s really language.
XML DOM Week 11 Web site:
JSON (Copied from and from Prof Da Silva) Week 12 Web site:
XML & JSON. Background XML and JSON are to standard, textual data formats for representing arbitrary data – XML stands for “eXtensible Markup Language”
11 jQuery Web Service Client. 22 Objectives You will be able to Use JSON (JavaScript Object Notation) for communcations between browser and server methods.
WELCOME MIDHUN SUDHAKAR twitter.com/midhunopus in.linkedin.com/pub/midhunsudhakar/86/a65/a9.
Introduction to AJAX Pat Morin COMP Outline What is AJAX? – History – Uses – Pros and Cons An XML HTTP Transaction – Creating an XMLHTTPRequest.
Introduction to Mongo DB(NO SQL data Base)
Storing Data.
Javascript and Dynamic Web Pages: Client Side Processing
Programming Web Pages with JavaScript
Introduction to Web programming
XML Parsers.
The Client-Server Model
Understanding XMLHttpRequest
AJAX AJAX = Asynchronous JavaScript and XML.
CS 371 Web Application Programming
AJAX and REST.
Callback Function function passed as a parameter to another function
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
Database Systems Week 12 by Zohaib Jan.
2017, Fall Pusan National University Ki-Joune Li
Consuming Java Script Object Notation (JSON) feeds
EXtensible Markup Language(XML)
XML stands for Extensible Markup Language.
Session V HTML5 APIs - AJAX & JSON
Week 11 Web site: XML DOM Week 11 Web site:
Built in Fairfield County: Front End Developers Meetup
Introduction to Web programming
HTML Level II (CyberAdvantage)
HTML5 AJAX & JSON APIs
2017, Fall Pusan National University Ki-Joune Li
Javascript & jQuery XML.
JavaScript & jQuery AJAX.
What is XML?.
2017, Fall Pusan National University Ki-Joune Li
Department of Computer Science Cal State East Bay, Hayward, CA
Exchange data interface
XML: Introduction to XML
CS 240 – Advanced Programming Concepts
Lecture 5- Semi-Structured Data (XML, JSON)
Semi-Structured Data (XML, JSON)
Web Technology Even Sem 2015
Both XML ad JSON are designed to transport data
Web Client Side Technologies Raneem Qaddoura
XML/JSON/AJAX Master a Skill / Learn for Life
JSON: JavaScript Object Notation
What is AJAX? AJAX is a developer's dream, because you can:
Extensible Markup Language (XML)
AJAX By Prof. B.A.Khivsara
XML: The new standard -Eric Taylor.
Presentation transcript:

Web Client Side Technologies 0780341 Raneem Qaddoura

XML

XML What is XML? XML stands for eXtensible Markup Language. XML was designed to store and transport data. XML was designed to be both human- and machine-readable.

XML Why Study XML? XML plays an important role in many different IT systems. XML is often used for distributing data over the Internet. It is important (for all types of software developers!) to have a good understanding of XML.

What is the DOM? The DOM defines a standard for accessing and manipulating documents. The HTML DOM defines a standard way for accessing and manipulating HTML documents. It presents an HTML document as a tree-structure. The XML DOM defines a standard way for accessing and manipulating XML documents. It presents an XML document as a tree-structure. Understanding the DOM is a must for anyone working with HTML or XML.

XML Tree Structure

XML Example <?xml version="1.0" encoding="UTF-8"?> <breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</price> <description> Two of our famous Belgian Waffles with plenty of real maple syrup </description> <calories>650</calories> </food> <name>Strawberry Belgian Waffles</name> <price>$7.95</price> Light Belgian waffles covered with strawberries and whipped cream <calories>900</calories> </breakfast_menu>

XML Parser The XML DOM (Document Object Model) defines the properties and methods for accessing and editing XML. However, before an XML document can be accessed, it must be loaded into an XML DOM object. All modern browsers have a built-in XML parser that can convert text into an XML DOM object. XML Parsing: Parsing an XML string Parsing an XML file using AJAX Parsing an XML file from API

Parsing an XML String <h2>Parsing a XML String</h2> <div> <b>To:</b> <span id="to"></span><br> <b>From:</b> <span id="from"></span><br> <b>Message:</b> <span id="message"></span> </div> <script> var txt, parser, xmlDoc; txt = "<note>" + "<to>Tove</to>" + "<from>Jani</from>" + "<heading>Reminder</heading>" + "<body>Don't forget me this weekend!</body>" + "</note>"; parser = new DOMParser(); xmlDoc = parser.parseFromString(txt,"text/xml"); document.getElementById("to").innerHTML = xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue; document.getElementById("from").innerHTML = xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue; document.getElementById("message").innerHTML = xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue; </script>

Parsing an XML File Using AJAX The XMLHttpRequest Object has a built in XML Parser. The responseXML property returns the response as an XML DOM object. If you want to use the response as an XML DOM object, you can use the responseXML property. For more information about ajax, read the following: intro XMLHttp Request Response

Parsing an XML File Using AJAX <?xml version="1.0" encoding="UTF-8"?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> <TITLE>Greatest Hits</TITLE> <ARTIST>Dolly Parton</ARTIST> <COMPANY>RCA</COMPANY> <YEAR>1982</YEAR> </CATALOG>

Parsing an XML File Using AJAX <h2>Parsing a XML File Using AJAX</h2> <button type="button" onclick="loadXMLDoc()">Get my CD collection</button> <p id="demo"></p> <script> function loadXMLDoc() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var x, i, xmlDoc, txt; xmlDoc = xmlhttp.responseXML; txt = ""; x = xmlDoc.getElementsByTagName("ARTIST"); for (i = 0; i< x.length; i++) { txt += x[i].childNodes[0].nodeValue + "<br>"; } document.getElementById("demo").innerHTML = txt; }; xmlhttp.open("GET", "cd_catalog.xml", true); xmlhttp.send(); </script>

Parsing an XML File from API <h2>Parsing A XML File from API</h2> <div> <b>Low:</b> <span id="low"></span><br> <b>High:</b> <span id="high"></span><br> <b>Sky:</b> <span id="sky"></span> </div> <script> var xmlhttp, xmlDoc; xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { xmlDoc = xmlhttp.responseXML; var myObj = xmlDoc.getElementsByTagName("forecast")[0]; document.getElementById("low").innerHTML = myObj.getAttribute('low'); document.getElementById("high").innerHTML = myObj.getAttribute('high'); document.getElementById("sky").innerHTML = myObj.getAttribute('skytextday'); } }; xmlhttp.open("GET", "http://weather.service.msn.com/data.aspx?weasearchstr=ny,NY&culture=en-US&weadegreetype=C&src=msn", true); xmlhttp.send(); </script>

JSON

JSON Syntax JSON Syntax Rules JSON syntax is derived from JavaScript object notation syntax: Data is in name/value pairs Data is separated by commas Curly braces hold objects Square brackets hold arrays var person = { name: "John", age: 31, city: "New York" }; person.name; // returns John person["name"]; // returns John

JSON Parse A common use of JSON is to exchange data to/from a web server. When receiving data from a web server, the data is always a string. Parse the data with JSON.parse(), and the data becomes a JavaScript object. JSON Parsing: Parsing an JSON string Parsing an JSON file using AJAX Parsing an JSON file from API Note: Download JSONView extension on chrome to view a formatted JSON file on the browser

Parsing a JSON String <h2>Parsing a JSON String</h2> <p id="demo"></p> <script> var txt = '{"name":"John", "age":30, "city":"New York"}' var obj = JSON.parse(txt); document.getElementById("demo").innerHTML = obj.name + ", " + obj.age; </script>

Parsing a JSON File Using AJAX You can request JSON from the server by using an AJAX request As long as the response from the server is written in JSON format, you can parse the string into a JavaScript object. For more information about ajax, read the following: intro XMLHttp Request Response

Parsing a JSON File Using AJAX { "name":"John", "age":31, "pets":[ { "animal":"dog", "name":"Fido" }, { "animal":"cat", "name":"Felix" }, { "animal":"hamster", "name":"Lightning" } ] }

Parsing a JSON File Using AJAX <h2>Parsing a JSON File Using AJAX</h2> <p id="demo"></p> <script> var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var myObj = JSON.parse(xmlhttp.responseText); document.getElementById("demo").innerHTML = myObj.name; } }; xmlhttp.open("GET", "json_demo.json", true); xmlhttp.send(); </script>

Parsing A JSON File from API <h2>Parsing A JSON File from API</h2> <p>Current temperature is <span id="demo"></span></p> <script> var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var myObj = JSON.parse(this.responseText); document.getElementById("demo").innerHTML = myObj[0].Temperature.Metric.Value + " " + myObj[0].Temperature.Metric.Unit; } }; xmlhttp.open("GET", "http://apidev.accuweather.com/currentconditions/v1/221790.json?language=en&apikey=hoArfRosT1215", true); xmlhttp.send(); </script>

JSON vs XML Both JSON and XML can be used to receive data from a web server. {"employees":[ { "firstName":"John", "lastName":"Doe" }, { "firstName":"Anna", "lastName":"Smith" }, { "firstName":"Peter", "lastName":"Jones" } ]} <employees> <employee> <firstName>John</firstName> <lastName>Doe</lastName> </employee> <firstName>Anna</firstName> <lastName>Smith</lastName> <firstName>Peter</firstName> <lastName>Jones</lastName> </employees>

JSON vs XML JSON is Like XML Because Both JSON and XML are "self describing" (human readable) Both JSON and XML are hierarchical (values within values) Both JSON and XML can be parsed and used by lots of programming languages Both JSON and XML can be fetched with an XMLHttpRequest JSON is Unlike XML Because JSON doesn't use end tag JSON is shorter JSON is quicker to read and write JSON can use arrays The biggest difference is:  XML has to be parsed with an XML parser. JSON can be parsed by a standard JavaScript function.

Why JSON is Better Than XML XML is much more difficult to parse than JSON. JSON is parsed into a ready-to-use JavaScript object. For AJAX applications, JSON is faster and easier than XML: Using XML Fetch an XML document Use the XML DOM to loop through the document Extract values and store in variables Using JSON Fetch a JSON string JSON.Parse the JSON string

References https://www.w3schools.com/ Sharma, P. (2013). Introduction to Web Technology. SK Kataria and Sons. Peterson, C. (2014). Learning responsive web design: a beginner's guide. " O'Reilly Media, Inc.".