CS 174: Web Programming April 16 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

XML: Extensible Markup Language
XML and Enterprise Computing. What is XML? Stands for “Extensible Markup Language” –similar to SGML and HTML –document “tags” are used to define content.
XML & Data Structures for the Internet Yingcai Xiao.
XML Introduction What is XML –XML is the eXtensible Markup Language –Became a W3C Recommendation in 1998 –Tag-based syntax, like HTML –You get to make.
XML(EXtensible Markup Language). XML XML stands for EXtensible Markup Language. XML is a markup language much like HTML. XML was designed to describe.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
Tutorial 11 Creating XML Document
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
Technical Track Session XML Techie Tools Tim Bornholt.
Chapter 13 XML Concept of XML Simple Example of XML XML vs. HTML in Syntax XML Structure DTD and CDATA Sections Concept of SAX Processing Download and.
PHP with XML Dequan Chen and Narith Kun ---Term Project--- for WSU 2010 Summer Course - CS366 s:
CS 174: Web Programming April 9 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
XML – Extensible Markup Language Sivakumar Kuttuva & Janusz Zalewski.
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.
CREATED BY ChanoknanChinnanon PanissaraUsanachote
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
XML and its applications: 4. Processing XML using PHP.
School of Computing and Management Sciences © Sheffield Hallam University To understand the Oracle XML notes you need to have an understanding of all these.
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.
Another PillowTalk Presentation  2004 Dynamic Systems, Inc. Introduction to XML for SOA Lee H. Burstein,
CS 157B: Database Management Systems II May 8 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
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.
Advanced Java Session 9 New York University School of Continuing and Professional Studies.
 XML is designed to describe data and to focus on what data is. HTML is designed to display data and to focus on how data looks.  XML is created to structure,
Session IV Chapter 9 – XML Schemas
CS 235: User Interface Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Electronic Commerce COMP3210 Session 4: Designing, Building and Evaluating e-Commerce Initiatives – Part II Dr. Paul Walcott Department of Computer Science,
Presentation Topic: XML and ASP Presented by Yanzhi Zhang.
WEB BASED DATA TRANSFORMATION USING XML, JAVA Group members: Darius Balarashti & Matt Smith.
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.
Accessing Data Using XML CHAPTER NINE Matakuliah: T0063 – Pemrograman Visual Tahun: 2009.
1 Overview of XSL. 2 Outline We will use Roger Costello’s tutorial The purpose of this presentation is  To give a quick overview of XSL  To describe.
CS 153: Concepts of Compiler Design September 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
XML and Its Applications Ben Y. Zhao, CS294-7 Spring 1999.
CS 157B: Database Management Systems II February 11 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
CS 157B: Database Management Systems II February 18 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
CS 174: Web Programming November 4 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
CS 157B: Database Management Systems II February 13 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
What is XML? eXtensible Markup Language eXtensible Markup Language A subset of SGML (Standard Generalized Markup Language) A subset of SGML (Standard Generalized.
Representing data with XML SE-2030 Dr. Mark L. Hornick 1.
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.
Martin Kruliš by Martin Kruliš (v1.1)1.
XML. RHS – SOC 2 Data vs. Information We often use the terms data and information interchangeably More precisely, data is some ”value” of a certain type,
CS 235: User Interface Design March 17 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
CHAPTER NINE Accessing Data Using XML. McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Introduction The eXtensible.
XML Extensible Markup Language
CS 174: Web Programming October 28 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
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.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
XML 1.Introduction to XML 2.Document Type Definition (DTD) 3.XML Parser 4.Example: CGI Gateway to XML Middleware.
I Copyright © 2004, Oracle. All rights reserved. Introduction.
XML: Extensible Markup Language
Unit 4 Representing Web Data: XML
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
XML in Web Technologies
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
Chapter 7 Representing Web Data: XML
XML Data Introduction, Well-formed XML.
2/18/2019.
XML and its applications: 4. Processing XML using PHP
Unit 6 - XML Transformations
Presentation transcript:

CS 174: Web Programming April 16 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Assignment #6  Add AJAX to your web application. Modify a portion of your web page (or dynamically create a menu or table) without a full page refresh.  Turn in the usual zip file containing source files, database dump, and screen shots.  Due Friday, April 24. 2

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak 3 XML  The Extensible Markup Language (XML) is an industry standard to: Store information. Describe the structure of that information. Exchange the information among different applications in a programming language- independent way.  Not all data comes from relational databases!

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak 4 XML Components  An XML element has an opening and a closing tag: The closing tag is mandatory.  An XML element may be nested in another element (child elements): XML documents that obey all the syntax rules are “well formed”

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak 5 XML Components, cont’d  An XML element may have content: An element can have both content and child elements.  An empty element has no content and no child elements. An empty element can be “self closed”. Macbeth William Shakespeare

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak 6 XML Components, cont’d  An XML element may have attributes Attribute values must be quoted. Attribute names must be unique within an element. Macbeth William Shakespeare

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak 7 XML Components, cont’d  Comments:  Begin every XML document with the processing instruction:

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak 8 XML Components, cont’d  Every XML document must have a single root element:

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak 9 Most Common XML Tools  Xpath “Path expressions” to locate a specific node (element, attribute, or content) or node sets within an XML document. Functions to compare, count, do arithmetic, extract substrings, etc.  XSLT Extensible Style Language for Transformation. Transform XML from one form to another (such as to HTML).

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak 10 Most Common XML Tools, cont’d  DTD Document Type Definition. Specify the schema of XML documents.  The DTD is itself not an XML document. Validate an XML document against its schema.

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak 11 Most Common XML Tools, cont’d  XML Schema XML Schema Definition (XSD). An alternate way to specify the schema of XML documents.  An XML Schema is itself an XML document.  A valid XML document is an instance of its schema.  XML schema : XML document  Java class : Java object

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak 12 Most Common XML Tools, cont’d  XML parsers Parse an XML document to obtain its information.  Object-XML mapping Perform object bindings.  Xquery A query language for data stored as XML.  Web services A way to transport XML data between applications.

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak XML Data on the Server  A data source for the web server can be XML.  The server must parse the XML data in order to understand its structure and extract its information.  Example: Parse XML data and convert it to HTML for download to a web browser. 13

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Expat: An “Event-Driven” XML Parser  The Expat parser is an XML parser for PHP.  As it parses XML data from start to end, “events” are fired each time it reads a start element tag an end element tag element contents  Callback functions process each event. 14

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Example XML Data: Courses 15 CS 149 Operating Systems Fundamentals: Contiguous and non-contiguous memory management; processor scheduling and interrupts; concurrent, mutually exclusive, synchronized and deadlocked processes; files. Substantial programming project required. CS 146 or SE 146 (with a grade of "C-" or better). courses.xml

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Example XML Data: Courses, cont’d 16 CS 153 Compiler Design Theoretical aspects of compiler design, including parsing context free languages, lexical analysis, translation specification and machine-independent code generation. Programming projects to demonstrate design topics. CS 47 or CMPE 102, CS 146, and CS 154 (with a grade of "C-" or better in each) or instructor consent. courses.xml

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Example XML Data: Courses, cont’d 17 CS 174 Web Programming Development and deployment of multi-tier web-based applications. Introduction to HTML, XML, enterprise design patterns, web services and database access. CS 46B (with a grade of "C-" or better). courses.xml

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Example XML Data: Courses, cont’d 18 CS 235 User Interface Design We will study the principles of designing, developing, and evaluating a compelling and effective user interface (UI) and experience (UX) for desktop, web, and mobile applications. User requirements and use cases UI and UX design patterns Usability testing CS 46B (with a grade of "C-" or better). courses.xml

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Expat Parsing for Structure 19 $(init); function init() { $("#output").load("structure.php"); } Structure Structure structure.html

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Expat Parsing for Structure, cont’d 20 $file = "courses.xml"; $depth = array(); function startElement($parser, $name, $attrs) { global $depth; if (!isset($depth[$parser])) { $depth[$parser] = 0; } for ($i = 0; $i < $depth[$parser]; $i++) { echo " "; } echo "$name\n"; $depth[$parser]++; } structure.php

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Expat Parsing for Structure, cont’d 21 function endElement($parser, $name) { global $depth; $depth[$parser]--; } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); if (!($fp = fopen($file, "r"))) { die("Could not open XML input."); } structure.php

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Expat Parsing for Structure, cont’d 22 while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } xml_parser_free($xml_parser); ?> Demo structure.php

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Expat Parsing: XML to HTML 23 $(init); function init() { $("#output").load("courses1.php"); } Expat Parser Courses by Expat Parser courses1.html

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Expat Parsing: XML to HTML, cont’d 24 function openElement($p, $element, $attributes) { switch ($element) { case "COURSE": { echo " "; break; } case "TITLE": { echo " "; break; } case "DESCRIPTION": { echo " "; break; } courses1.php

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Expat Parsing: XML to HTML, cont’d 25 case "PREQUISITES": { echo " Prerequisites "; break; } case "TOPICS": { echo " "; break; } case "TOPIC": { echo " "; break; } courses1.php

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Expat Parsing: XML to HTML, cont’d 26 function closeElement($p, $element) { switch ($element) { case "COURSE": { echo " "; break; } case "TITLE": { echo " "; break; } case "DESCRIPTION": { echo " "; break; } courses1.php

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Expat Parsing: XML to HTML, cont’d 27 case "PREQUISITES": { echo " "; break; } case "TOPICS": { echo " "; break; } case "TOPIC": { echo " "; break; } courses1.php

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Expat Parsing: XML to HTML, cont’d 28 function characterData($p, $cdata) { echo $cdata; } $parser = xml_parser_create(); xml_set_element_handler($parser, "openElement", "closeElement"); xml_set_character_data_handler($parser, "characterData"); courses1.php

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Expat Parsing: XML to HTML, cont’d 29 $file = "courses.xml"; $fp "r") or die(" Could not open a file called '$file'.". " "); while ($data = fread($fp, 4096)) { xml_parse($parser, $data, feof($fp)); } xml_parser_free($parser); ?> courses1.php Demo

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak Expat Advantages and Disadvantages  Advantages Very fast One pass Can handle arbitrarily large XML data.  Disadvantages Inflexible Must process the stream of “events” as they occur. The parser may become large. 30

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak “Simple”: A DOM-Based Parser  “Simple” is a DOM-based XML parser for PHP.  As it parses XML data, it builds a DOM tree.  Walk the tree in order to obtain its information. 31

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak “Simple”: A DOM-Based Parser, cont’d 32 <?php $xml = simplexml_load_file("courses.xml"); foreach ($xml->course as $course) { echo " $course->title "; echo " $course->description "; if (isset($course->topics)) { echo " "; $topics = $course->topics; foreach ($topics->topic as $topic) { echo " $topic "; } echo " "; } echo " Prerequisites $course- >prequisites "; echo " "; } ?> courses2.php Demo

Computer Science Dept. Spring 2015: April 16 CS 174: Web Programming © R. Mak “Simple” Advantages and Disadvantages  Advantages More straightforward, structure-aware code. The parser can be small.  Disadvantages Must understand the structure of the XML data in order to walk the DOM tree properly. Building the DOM tree in memory limits the size of the XML data that can be parsed. 33