Server-Side Application and Data Management IT IS 3105 (FALL 2009)

Slides:



Advertisements
Similar presentations
SPECIAL TOPIC XML. Introducing XML XML (eXtensible Markup Language) ◦A language used to create structured documents XML vs HTML ◦XML is designed to transport.
Advertisements

3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures.
XML Parsing Using Java APIs AIP Independence project Fall 2010.
Extensible Markup Language XML MIS 520 – Database Theory Fall 2001 (Day) Lecture 14.
XML(EXtensible Markup Language). XML XML stands for EXtensible Markup Language. XML is a markup language much like HTML. XML was designed to describe.
Tutorial 11 Creating XML Document
XML Primer. 2 History: SGML vs. HTML vs. XML SGML (1960) XML(1996) HTML(1990) XHTML(2000)
PHP with XML Dequan Chen and Narith Kun ---Term Project--- for WSU 2010 Summer Course - CS366 s:
PHP and XML TP2653 Advance Web Programming. PHP and XML PHP5 – XML-based extensions, library and functionalities (current XAMPP PHP version is )
XML introduction to Ahmed I. Deeb Dr. Anwar Mousa  presenter  instructor University Of Palestine-2009.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
CREATED BY ChanoknanChinnanon PanissaraUsanachote
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
XML eXtensible Markup Language w3c standard Why? Store and transport data Easy data exchange Create more languages WSDL (Web Service Description Language)
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.
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.
XML Extensible Markup Language. What is XML? An infrastructure for describing text and data Developed by W3C(the World Wide Web Consortium)
Session IV Chapter 9 – XML Schemas
Electronic Commerce COMP3210 Session 4: Designing, Building and Evaluating e-Commerce Initiatives – Part II Dr. Paul Walcott Department of Computer Science,
Avoid using attributes? Some of the problems using attributes: Attributes cannot contain multiple values (child elements can) Attributes are not easily.
XML eXtensible Markup Language. Topics  What is XML  An XML example  Why is XML important  XML introduction  XML applications  XML support CSEB.
XML – An Introduction Structured Data Mark-up James McCartney CSCE 590, Cluster and Grid Computing.
Softsmith Infotech XML. Softsmith Infotech XML EXtensible Markup Language XML is a markup language much like HTML Designed to carry data, not to display.
Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Scripting with the DOM Ellen Pearlman Eileen Mullin Programming the Web.
XML Documents Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University Elements Attributes Comments PI Document.
Advanced PHP & RSS Utilizing XML, RSS, and PHP. XML (eXtensible Markup Language) XML is the language of all RSS feeds and subscriptions XML is basically.
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.
Web Technologies COMP6115 Session 4: Adding a Database to a Web Site Dr. Paul Walcott Department of Computer Science, Mathematics and Physics University.
The eXtensible Markup Language (XML). Presentation Outline Part 1: The basics of creating an XML document Part 2: Developing constraints for a well formed.
An Introduction to XML Paul Donohue May 8th 2002 Hotel Senator Zürich.
XML Design Goals 1.XML must be easily usable over the Internet 2.XML must support a wide variety of applications 3.XML must be compatible with SGML 4.It.
1 Tutorial 11 Creating an XML Document Developing a Document for a Cooking Web Site.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 10.
Well Formed XML The basics. A Simple XML Document Smith Alice.
What is XML? eXtensible Markup Language eXtensible Markup Language A subset of SGML (Standard Generalized Markup Language) A subset of SGML (Standard Generalized.
 defined as Extensible Markup Language (XML) is a set of rules for encoding documents  Defines structure and data.
CO1552 – Web Application Development Further JavaScript: Part 1: The Document Object Model Part 2: Functions and Events.
XML CSC1310 Fall HTML (TIM BERNERS-LEE) HyperText Markup Language  HTML (HyperText Markup Language): December  Markup  Markup is a symbol.
XML DOM Week 11 Web site:
XML Introduction to XML Extensible Markup Language.
XML & JSON. Background XML and JSON are to standard, textual data formats for representing arbitrary data – XML stands for “eXtensible Markup Language”
XML 1.Introduction to XML 2.Document Type Definition (DTD) 3.XML Parser 4.Example: CGI Gateway to XML Middleware.
Week-9 (Lecture-1) XML DTD (Data Type Document): An XML document with correct syntax is called "Well Formed". An XML document validated against a DTD is.
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.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
Unit 4 Representing Web Data: XML
Unit M Programming Web Pages with
Parsing XML XDocument and LINQ
Unit M Programming Web Pages with
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
XML in Web Technologies
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
XML stands for Extensible Markup Language.
The XML Language.
CHAPTER 9 JAVA AND XML.
Week 11 Web site: XML DOM Week 11 Web site:
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
More Sample XML By Sadia Anjum.
XML Parsing In PHP.
Javascript & jQuery XML.
What is XML?.
CS 240 – Advanced Programming Concepts
XML and its applications: 4. Processing XML using PHP
Allyson Falkner Spokane County ISD
XML Programming in Java
Extensible Markup Language (XML)
Presentation transcript:

Server-Side Application and Data Management IT IS 3105 (FALL 2009) XML and PHP Mohamed Shehab Lecture 8

Working with XML The name XML comes from the full name of the language, Extensible Markup Language. XML is a method of data exchange, in that it holds well-defined content within its boundaries. XML Separates Data from HTML XML Simplifies Data Sharing XML Simplifies Data Transport XML Simplifies Platform Changes

<root> <child id=“1”> <subchild> <root> <child id=“1”> <subchild>.....</subchild> </child> <child id=“2”> </root>

XML Structure XML documents contain two major elements: the prolog and the body. The prolog contains the XML declaration statement and any processing instructions and comments you want to add. The body contains the content structure is contained.

XML Structure (example.xml) <?xml version="1.0" ?> <!-- Sample XML document --> <Books> <Book id=‘1’> <Author> Vikram Vaswani </Author> <Title> PHP A Beginner’s Guide </Title> <Edition> 1</Edition> <Year> 2009 </Year> <ISBN> 0-07-154902-1 </ISBN> </Book> </Books>

XML Structure There is only one root element in an XML document. In the previous example the root element is Books. All subsequent elements are referred to as children elements. XML Attributes provide additional information about elements. XML Attribute Values Must be Quoted XML is case sensitive, so <Book> and <book> are different elements. All XML tags must be properly closed, XML tags must be properly nested, and no overlapping tags are allowed.

Well Formed XML A "Well Formed" XML document has correct XML syntax. The syntax rules: XML documents must have a root element XML elements must have a closing tag XML tags are case sensitive XML elements must be properly nested XML attribute values must be quoted

XML Parsing Methods Simple API for XML (SAX) parser: works by traversing an XML document sequentially, from beginning to end, and calling specific user-defined functions as it encounters different types of XML constructs. Document Object Model (DOM) parser: works by reading the entire XML document in one step and converting it to a hierarchical “tree” structure in memory. The parser can then be programmed to traverse the tree, jumping between “sibling” or “child” branches of the tree to access specific pieces of information.

SAX and DOM SAX reads XML data in “chunks” and is efficient for large files, but it requires the programmer to create customized functions to handle the different elements in an XML file. DOM requires less customization but can rapidly consume memory for its actions and so is often unsuitable for large XML data files. The choice of method thus depends heavily on the requirements of the application in question.

Using the SimpleXML PHP Extension PHP supports both SAX and DOM parsing methods. The SimpleXML extension provides a user-friendly and intuitive interface to read and process XML data. SimpleXML represents every XML document as an object and turns the elements within it into a hierarchical set of objects and object properties. Accessing a particular element now becomes as simple as using parent->child notation to traverse the object tree until that element is reached.

XML Tree Structure <?xml version='1.0'?> <address> <street>13 High Street</street> <county>Oxfordshire</county> <city> <name>Oxford</name> <zip>OX1 1BA</zip> </city> <country>UK</country> </address> address street county city name zip country

SimpleXML: Reading XML Tree address street county city name zip country <?php $xml = simplexml_load_file('address.xml') or die (“Cant load XML!"); echo "City: " . $xml->city->name . "\n"; echo "Postal code: " . $xml->city->zip . "\n"; ?>

SimpleXML: Accessing Elements Accessing elements within an XML document that contain characters not permitted under PHP's naming convention (e.g. the hyphen) can be accomplished by encapsulating the element name within braces and the apostrophe. <?xml version='1.0'?> <activity> <name> Business Meeting </name> <start-date>Mon, 21 Sep 2009 10:30:00 EDT</start-date> <end-date>Mon, 21 Sep 2009 11:30:00 EDT</end-date> </activity> <?php $xml = simplexml_load_file('activity.xml') or die (“Cant load XML!"); echo “Name: " . $xml->name . "\n"; echo “Start Date: " . $xml->{‘start-date’} . “<br>"; echo “End Date: " . $xml->{‘end-date’} . “<br>"; ?>

SimpleXML: Multiple element instances library book title author year Multiple instances of the same element at the same level of the XML document tree are represented as arrays. Can easily be presented by the loops.

SimpleXML: Multiple element instances library book title author year <?php $xml = simplexml_load_file(‘library.xml') or die (“Cant load XML!"); foreach ($xml->book as $book) { echo $book->title . “ is written by “ . $book->author . “<br>”; } ?>

SimpleXML: Counting multiple Elements Use the count() function: <?php $xml = simplexml_load_file(‘library.xml') or die (“Cant load XML!"); echo count($xml->book) . ‘ book(s) found <br>’; ?>

SimpleXML: Reading Attributes SimpleXML has an easy way to get to the attributes attributes and values are converted into keys and values of a PHP associative array and can be accessed like regular array elements.

SimpleXML: Reading Attributes <?xml version="1.0"?> <library> <book id="1" genre="horror" rating="5"> <title>The Shining</title> <author>Stephen King</author> <pages>673</pages> </book> … </library> <?php $xml = simplexml_load_file(‘library.xml') or die (“Cant load XML!"); foreach ($xml->book as $book) { echo $book->title . “ is written by “ . $book->author . “ genre is ”. $book[‘genre’] . “ and rating is “ . $book[‘rating’] .”<br>”; } ?>

Reading RSS Files rss channel title link pubDate ttl item description