COMP9321 Web Application Engineering

Similar documents
COMP9321 Web Application Engineering

COMP9321 Web Application Engineering. Extensible Markup Language (XML)

XML. Presented by : Guerreiro João Thanh Truong Cong

CS6501 IP Unit IV Page 1

CSC Web Technologies, Spring Web Data Exchange Formats

EXtensible Markup Language (XML) a W3C standard to complement HTML A markup language much like HTML

7.1 Introduction. extensible Markup Language Developed from SGML A meta-markup language Deficiencies of HTML and SGML

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 7 XML

Delivery Options: Attend face-to-face in the classroom or remote-live attendance.

EXtensible Markup Language XML

XML: Introduction. !important Declaration... 9:11 #FIXED... 7:5 #IMPLIED... 7:5 #REQUIRED... Directive... 9:11

Introduction to XML. XML: basic elements

CSI 3140 WWW Structures, Techniques and Standards. Representing Web Data: XML

Chapter 1: Getting Started. You will learn:

Delivery Options: Attend face-to-face in the classroom or via remote-live attendance.

So, if you receive data from a server, in JSON format, you can use it like any other JavaScript object.

11. EXTENSIBLE MARKUP LANGUAGE (XML)

XML: Extensible Markup Language

The main problem of DTD s...

Introduction to JSON. Roger Lacroix MQ Technical Conference v

Intro to XML. Borrowed, with author s permission, from:

The XML Metalanguage

XML. Objectives. Duration. Audience. Pre-Requisites

XML. Jonathan Geisler. April 18, 2008

- What is a markup language? - What is a data serialization language?

COMP9321 Web Application Engineering

COMP9321 Web Application Engineering

extensible Markup Language

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 27-1


extensible Markup Language

Comp 336/436 - Markup Languages. Fall Semester Week 4. Dr Nick Hayward

Data Exchange. Hyper-Text Markup Language. Contents: HTML Sample. HTML Motivation. Cascading Style Sheets (CSS) Problems w/html

The concept of DTD. DTD(Document Type Definition) Why we need DTD

Comp 336/436 - Markup Languages. Fall Semester Week 4. Dr Nick Hayward

Chapter 13 XML: Extensible Markup Language

Data Presentation and Markup Languages

M359 Block5 - Lecture12 Eng/ Waleed Omar

Structured documents

extensible Markup Language

XML Metadata Standards and Topic Maps

.. Cal Poly CPE/CSC 366: Database Modeling, Design and Implementation Alexander Dekhtyar..

Introduction to XML. Asst. Prof. Dr. Kanda Runapongsa Saikaew Dept. of Computer Engineering Khon Kaen University

W3C XML XML Overview

Markup Languages SGML, HTML, XML, XHTML. CS 431 February 13, 2006 Carl Lagoze Cornell University

Introduction to XML 3/14/12. Introduction to XML

CSS, Cascading Style Sheets

Java EE 7: Back-end Server Application Development 4-2

A tutorial report for SENG Agent Based Software Engineering. Course Instructor: Dr. Behrouz H. Far. XML Tutorial.

XML: Managing with the Java Platform

IT2353 WEB TECHNOLOGY Question Bank UNIT I 1. What is the difference between node and host? 2. What is the purpose of routers? 3. Define protocol. 4.

Introduction to XML DTD

EMERGING TECHNOLOGIES. XML Documents and Schemas for XML documents

Well-formed XML Documents

XML Extensible Markup Language

Grid Computing. What is XML. Tags, elements, and attributes. Valid and well formed XML. Grid Computing Fall 2006 Paul A.

Introduction to Semistructured Data and XML. Overview. How the Web is Today. Based on slides by Dan Suciu University of Washington

Web Programming Paper Solution (Chapter wise)

Outline. XML vs. HTML and Well Formed vs. Valid. XML Overview. CSC309 Tutorial --XML 4. Edward Xia

Author: Irena Holubová Lecturer: Martin Svoboda

COPYRIGHTED MATERIAL. Contents. Part I: Introduction 1. Chapter 1: What Is XML? 3. Chapter 2: Well-Formed XML 23. Acknowledgments

SRI VIDYA COLLEGE OF ENGINEERING & TECHNOLOGY- VIRUDHUNAGAR

Introduction to XML Zdeněk Žabokrtský, Rudolf Rosa

KINGS COLLEGE OF ENGINEERING 1

XML 2 APPLICATION. Chapter SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.

What is XML? XML is designed to transport and store data.

AJAX ASYNCHRONOUS JAVASCRIPT AND XML. Laura Farinetti - DAUIN

XML & Related Languages

B.V.Patel Institute of Business Management, Computer & Information Technology, UTU

Overview. Introduction. Introduction XML XML. Lecture 16 Introduction to XML. Boriana Koleva Room: C54

XML Primer Plus By Nicholas Chase

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

Introduction to XML. Chapter 133

Extensible Markup Language (XML) Hamid Zarrabi-Zadeh Web Programming Fall 2013

Agenda. XML Generics. XML for Java Developers G Session 1 - Main Theme Markup Language Technologies (Part I)

COMP9321 Web Application Engineering

XML Namespaces. Mario Arrigoni Neri

XML. extensible Markup Language. Overview. Overview. Overview XML Components Document Type Definition (DTD) Attributes and Tags An XML schema

x ide xml Integrated Development Environment Specifications Document 1 Project Description 2 Specifi fications

XML. Marie Dubremetz Uppsala, April 2014

AIM. 10 September

markup language carry data define your own tags self-descriptive W3C Recommendation

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

COPYRIGHTED MATERIAL. Introduction to XML

7.1 Introduction. 7.1 Introduction (continued) - Problem with using SGML: - SGML is a meta-markup language

Web Services Part I. XML Web Services. Instructor: Dr. Wei Ding Fall 2009

XML. extensible Markup Language. ... and its usefulness for linguists

XML: some structural principles

HTML and XML. XML stands for extensible Markup Language

2009 Martin v. Löwis. Data-centric XML. XML Syntax

XML. COSC Dr. Ramon Lawrence. An attribute is a name-value pair declared inside an element. Comments. Page 3. COSC Dr.

Web Technologies Present and Future of XML

Introduction p. 1 An XML Primer p. 5 History of XML p. 6 Benefits of XML p. 11 Components of XML p. 12 BNF Grammar p. 14 Prolog p. 15 Elements p.

SDPL : XML Basics 2. SDPL : XML Basics 1. SDPL : XML Basics 4. SDPL : XML Basics 3. SDPL : XML Basics 5

Chapter 7: XML Namespaces

Introduction Syntax and Usage XML Databases Java Tutorial XML. November 5, 2008 XML

Publishing Technology 101 A Journal Publishing Primer. Mike Hepp Director, Technology Strategy Dartmouth Journal Services

Chapter 10: Understanding the Standards

Web Standards Mastering HTML5, CSS3, and XML

~ Ian Hunneybell: DIA Revision Notes ~

Transcription:

COMP9321 Web Application Engineering Semester 2, 2017 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 http://webapps.cse.unsw.edu.au/webcms2/course/index.php?cid= 2465 1

Extensible Markup Language (XML) XML is a markup language much like HTML Designed to describe data. XML tags are not predefined. Designed to display data. HTML tags are predefined. XML: is a W3C Recommendation is designed to be self-descriptive is derived from SGML (ISO 8879). originally designed to meet the challenges of large-scale electronic publishing. 2

Extensible Markup Language (XML) XML separates presentation issues from the actual data. 3

Extensible Markup Language (XML) 4

Extensible Markup Language (XML) XML plays an increasingly important role in the exchange of a wide variety of data on the Web and elsewhere. Online Book Store Example (Lec01 Revisit) Buy Book? Internet mybook.com 5

Extensible Markup Language (XML) XML plays an increasingly important role in the exchange of a wide variety of data on the Web and elsewhere. springer.com/ Amazon.com ieee.org Buy Book? Internet mybook.com 6

Extensible Markup Language (XML) XML plays an increasingly important role in the exchange of a wide variety of data on the Web and elsewhere. springer.com/ Amazon.com Buy Book? Internet ieee.org Presentation Logic Data mybook.com 7

Extensible Markup Language (XML) XML plays an increasingly important role in the exchange of a wide variety of data on the Web and elsewhere. springer.com/ Amazon.com Buy Book? Internet ieee.org Presentation Logic Data mybook.com 8

Extensible Markup Language (XML) XML plays an increasingly important role in the exchange of a wide variety of data on the Web and elsewhere. springer.com/ Amazon.com Buy Book? Internet ieee.org Presentation Logic Data mybook.com 9

Extensible Markup Language (XML) XML plays an increasingly important role in the exchange of a wide variety of data on the Web and elsewhere. springer.com/ Amazon.com Buy Book? Internet ieee.org Presentation Logic Data mybook.com Communication protocol? SOAP Google(Simple Object Access Protocol) Simple Object Access Protocol 10

Why XML? 11

Why XML? 12

Why XML? 13

Separating the Content from Presentation HTML was designed to display data. CSS: Cascading Style Sheets CSS defines how HTML elements are to be displayed All formatting could be removed from the HTML document, and stored in a separate CSS file. XML was designed to describe data. 14

Separating the Content from Presentation 15

XML Applications 16

XML Applications RSS : Really Simple Syndication With RSS it is possible to distribute up-to-date web content from one web site to thousands of other web sites around the world. RSS is written in XML RSS allows you to syndicate your site content RSS defines an easy way to share and view headlines and content RSS files can be automatically updated RSS allows personalized views for different sites RSS is useful for web sites that are updated frequently, like: e.g. News sites, Companies, and Calendars. Without RSS, users will have to check your site daily for new updates. 17

XML Applications RSS : Really Simple Syndication With RSS it is possible to distribute up-to-date web content from one web site to thousands of other web sites around the world. RSS is written in XML RSS allows you to syndicate your site content RSS defines an easy way to share and view headlines and content RSS files can be automatically updated RSS allows personalized views for different sites RSS is useful for web sites that are updated frequently, like: e.g. News sites, Companies, and Calendars. Without RSS, users will have to check your site daily for new updates. 18

XML is 19

Quick XML syntax 20

The XML Family XML: a markup language used to describe information. 21

The XML Family XML: a markup language used to describe information. DOM: The Document Object Model (DOM) is an application programming interface (API) for valid HTML and well-formed XML documents. DOM Defines: the logical structure of documents; the way a document is accessed and manipulated; A graphical representation of the DOM of the example table https://www.w3.org/tr/dom-level-2-core/introduction.html 22

The XML Family XML: a markup language used to describe information. DOM: The Document Object Model (DOM) is an application programming interface (API) for valid HTML and well-formed XML documents. The DOM is separated into 3 different parts/levels: Core DOM - standard model for any structured document XML DOM - standard model for XML documents A standard object model for XML A standard programming interface for XML Platform- and language-independent HTML DOM - standard model for HTML documents 23

The XML Family XML: a markup language used to describe information. DOM: The Document Object Model (DOM) is an application programming interface (API) for valid HTML and well-formed XML documents. The DOM is separated into 3 different parts/levels: Core DOM - standard model for any structured document XML DOM - standard model for XML documents A standard object model for XML A standard programming interface for XML Platform- and language-independent HTML DOM - standard model for HTML documents 24

The XML Family XML: a markup language used to describe information. DOM: a programming interface for accessing and updating documents. DTD: A Document Type Definition (DTD) defines the structure and the legal elements and attributes of an XML document. from a DTD point of view, all XML documents are made up by the following building blocks: Elements: <student> </student> Attributes: <student id= 50001 > </student> Entity References: < > & " &apos; 25

The XML Family XML: a markup language used to describe information. DOM: a programming interface for accessing and updating documents. DTD: A Document Type Definition (DTD) defines the structure and the legal elements and attributes of an XML document. from a DTD point of view, all XML documents are made up by the following building blocks: Elements: <student> </student> Attributes: <student id= 50001 > </student> Entity References: < > & " &apos; The character data inside an element must not contain certain characters with special meanings. You must escape the characters using entity references.. <mytag> if x > 5 </mytag> <mytag> if x > 5 </mytag> <mybook pub= O Reilly > Programming </mybook > <mybook pub= O&apos;Reilly > Programming</myBook> 26

The XML Family XML: a markup language used to describe information. DOM: a programming interface for accessing and updating documents. DTD: A Document Type Definition (DTD) defines the structure and the legal elements and attributes of an XML document. from a DTD point of view, all XML documents are made up by the following building blocks: Elements: <student> </student> Attributes: <student id= 50001 > </student> Entities: < > & " &apos; PCDATA (Parsed Character DATA): is the text that WILL be parsed by a parser. CDATA (Character DATA) is the text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and entities will not be expanded. 27

Phonebook.xml with Internal DTD 28

Phonebook.xml with External DTD. Phonebook.dtd 29

CDATA Section 30

Defining XML Content: Elements 31

Defining XML Content: Modifiers 32

Defining XML Content: Choices, Empty 33

Defining XML Content: Mixed content, Any 34

Defining XML Content: Creating Attributes 35

Defining XML Content: Creating Attributes Use the #REQUIRED keyword if you don't have an option for a default value, but still want to force the attribute to be present. Use the #IMPLIED keyword if you don't want to force the author to include an attribute, and you don't have an option for a default value. Use the #FIXED keyword when you want an attribute to have a fixed value without allowing the author to change it. If an author includes another value, the XML parser will return an error. 36

Defining XML Content: Creating Attributes 37

XML Custom Entities 38

Parameter Entities The purpose of a parameter entity is to enable you to create reusable sections of replacement text. <!ENTITY % ename "entity_value"> Example: <!ELEMENT residence (name, street, pincode, city, phone)> <!ELEMENT apartment (name, street, pincode, city, phone)> <!ELEMENT office (name, street, pincode, city, phone)> <!ELEMENT shop (name, street, pincode, city, phone)> <!ENTITY % area "name, street, pincode, city"> <!ENTITY % contact "phone"> <!ELEMENT residence (%area;, %contact;)> <!ELEMENT apartment (%area;, %contact;)> <!ELEMENT office (%area;, %contact;)> <!ELEMENT shop (%area;, %contact;)> 39

Parameter Entities 40

Well-formedness and Validity of XML 41

Limitations of DTD 42

The XML Family XML: a markup language used to describe information. DOM: a programming interface for accessing and updating documents. DTD: describes the structure and content of XML documents. XML Schema: is an XML-based alternative to DTD. describes the structure of an XML document. defines elements and attributes that can appear in a document defines data types for elements and attributes defines default and fixed values for elements and attributes defines the child elements, their orders, etc. XML Schemas are much more powerful than DTDs. The XML Schema language is also referred to as XML Schema Definition (XSD). 43

The XML Family XML: a markup language used to describe information. DOM: a programming interface for accessing and updating documents. DTD: describes the structure and content of XML documents. XML Schema: XML Schema - W3C's recommendation for replacing DTD with features such as: Simple and complex data types Type derivation and inheritance Namespace-aware element and attributes Limits on number of appearances by an element Combining with regular expressions for finer control over document structure Most importantly, XML Schemas are well-formed XML documents themselves. But first, what is a namespace? 44

XML Namespaces 45

XML Namespaces (example) 46

XML Namespaces 47

Previous examples can now be... 48

XML Namespace Syntax When using prefixes in XML, a namespace for the prefix must be defined. The namespace can be defined by an xmlns attribute in the start tag of an element. The namespace declaration has the following syntax: xmlns:prefix="uri Name conflicts in XML can easily be avoided using a name prefix. <root> <table> <tr> <td>apples</td> <td>bananas</td> </tr> </table> <table> <name>african Coffee Table</name> <width>80</width> <length>120</length> </table> <h:table xmlns:h="http://www.w3.org/tr/html4/"> <h:tr> <h:td>apples</h:td> <h:td>bananas</h:td> </h:tr> </h:table> <f:table xmlns:f="http://www.w3schools.com/furniture"> <f:name>african Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </root> 49

XML Namespace Syntax <root xmlns:h = http://www.w3.org/tr/html4/ xmlns:f = "http://www.w3c.com/furniture > When using prefixes in XML, a namespace for the prefix must be defined. The namespace can be defined by an xmlns attribute in the start tag of an element. <h:table> The namespace declaration has the following syntax: <h:tr> <h:td>apples</h:td> xmlns:prefix="uri Name conflicts <h:td>bananas</h:td> in XML can easily be avoided using a name prefix. </h:tr> <root> </h:table> <table> <tr> <td>apples</td> <td>bananas</td> </tr> </table> <f:table> <f:name>african Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> <table> <name>african </root> Coffee Table</name> <width>80</width> <length>120</length> </table> <h:table xmlns:h="http://www.w3.org/tr/html4/"> <h:tr> <h:td>apples</h:td> <h:td>bananas</h:td> </h:tr> </h:table> <f:table xmlns:f="http://www.w3schools.com/furniture"> <f:name>african Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </root> 50

XML Schema Definition (XSD) a recommendation of the World Wide Web Consortium (W3C) specifies how to formally describe the elements in an Extensible Markup Language (XML) document. 51

Simple Types 52

Attributes 53

Type Restrictions 54

Complex Types 55

Complex Types 56

The XML Family XML: a markup language used to describe information. DOM: a programming interface for accessing and updating documents. DTD and XML Schema: describes the structure and content of XML documents. XSLT: XSL stands for extensible Stylesheet Language, and is a style sheet language for XML documents. CSS = Style Sheets for HTML XSL = Style Sheets for XML XSL describes how the XML document should be displayed! XSLT (XSL Transformations) a language for transforming XML documents. 57

The XML Family XML: a markup language used to describe information. DOM: a programming interface for accessing and updating documents. DTD and XML Schema: describes the structure and content of XML documents. XSLT: a language for transforming XML documents 58

The XML Family XML: a markup language used to describe information. DOM: a programming interface for accessing and updating documents. DTD and XML Schema: describes the structure and content of XML documents. XSLT: a language for transforming XML documents XPath: XPath (XML Path language) is a language for finding information in an XML document. XPath contains a library of standard functions XPath is a major element in XSLT XPath is also used in XQuery, XPointer and XLink XPath is a W3C recommendation 59

The XML Family XML: <?xml a version="1.0" markup language.> used to describe some XPath information. expressions: <comp9321_students> DOM: a programming interface for accessing and updating documents. <student> /comp9321_student/student[1] DTD <id>50001</id> and XML Schema: describes the Selects structure the first and student content element of XML that documents. is the child XSLT: <name>adam a language B.</name> for transforming XML of the documents comp9321_student element XPath: <program>8543</program> XPath <stage>1</stage> (XML Path language) is a language /comp9321_student/student[last()] for finding information in an XML </student> document. Selects the last student element that is the child of the comp9321_student element <student> XPath contains a library of standard functions XPath <id>50002</id> is a major element in XSLT /comp9321_student/student[position()<3] XPath <name>alex is also C.</name> used in XQuery, XPointer Selects the and first XLink two student element that is the <program>3978</program> XPath is a W3C recommendation child of the comp9321_student element <stage>3</stage> </student> /comp9321_student/student[stage>2] </comp9321_students> Selects all the student elements of the comp9321_student element that have a stage element with a value greater than 2. 60

The XML Family XML: a markup language used to describe information. DOM: a programming interface for accessing and updating documents. DTD and XML Schema: describes the structure and content of XML documents. XSLT: a language for transforming XML documents XPath: a query language for navigating XML documents. XPointer: for identifying fragments of a document. XLink: generalises the concept of a hypertext link. XInclude: for merging documents. XQuery: a language for making queries across documents. RDF: a language for describing resources. 61

An XML document is a tree... 62

Attributes in XML tags 63

Attributes in XML tags 64

Parsing XML documents with Java 65

Parsing XML documents with Java 66

SAX and DOM as the Standard Interfaces 67

Document Object Model (DOM) 68

Dealing with Nodes in DOM 69

An example XML here... 70

DOM for XML 71

Using a DOM Parser (eg., Apache Xerces) 72

Document Interface Methods 73

Examples of Node Properties (XML), p.9.25 74

Count/Print the number of 'book' elements 75

Dealing with Nodes in DOM The method getnodetype() returns the number in the range 1 to 12. 76

More with DOM... 77

JSON (JavaScript Object Notation) 78

JSON JSON is a syntax for storing and exchanging data. JSON is an easier-to-use alternative to XML. XML: JSON: JSON uses JavaScript syntax, but the JSON format is text only, just like XML. 79

JSON JSON is a syntax for storing and exchanging data. JSON is an easier-to-use alternative to XML. XML: JSON: JSON uses JavaScript syntax, but the JSON format is text only, just like XML. 80

JSON The JSON format is syntactically identical to the code for creating JavaScript objects. Instead of using a parser (like XML does), a JavaScript program can use standard JavaScript functions to convert JSON data into native JavaScript objects. 81

JSON XML has to be parsed with an XML parser. JSON can be parsed by a standard JavaScript function. 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. http://www.slideshare.net/ibrahimalibrahim1/xml-vs-json-47487221 82

JSON JSON Data: "name": " value A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested. 83

JSON JSON Data: "name": " value JSON Objects: An object is an unordered set of name/value pairs. An object begins with { and ends with } Each name is followed by : (colon) the name/value pairs are separated by, (comma). {"firstname":"john", "lastname":"doe"} 84

JSON JSON Data: "name": " value JSON Objects: {"firstname":"john", "lastname":"doe"} JSON Arrays: An array is an ordered collection of values An array begins with [ and ends with ] Values are separated by, (comma). "employees":[ {"firstname":"john", "lastname":"doe"}, {"firstname":"anna", "lastname":"smith"}, {"firstname":"peter","lastname":"jones"} ] 85

JSON JSON Data: "name": " value JSON Objects: {"firstname":"john", "lastname":"doe"} JSON Arrays: "employees":[ {"firstname":"john", "lastname":"doe"}, {"firstname":"anna", "lastname":"smith"}, {"firstname":"peter","lastname":"jones"} ] JSON Files: The file type for JSON files is ".json" The MIME type for JSON text is "application/json" 86

JSON Http Request A common use of JSON is to read data from a web server, and display the data in a web page. data.json browser 87

JSON Http Request A common use of JSON is to read data from a web server, and display the data in a web page. data.json browser 88

JSON Http Request A common use of JSON is to read data from a web server, and display the data in a web page. data.json browser Create a JavaScript function to display the array. 89

JSON Http Request A common use of JSON is to read data from a web server, and display the data in a web page. data.json browser Write an XMLHttpRequest to read the file, and use myfunction() to display the array 90

References http://www.w3.org/xml/ XML in a nutshell, Chapters 9 and 10 http://www.ibm.com/developerworks/library/xml-schema/ http://www.w3schools.com/ http://www.json.org/ Some examples in these notes are originated from Dr. David Edmond from QUT, Brisbane 91

92