UFCEKG-20-2 Data, Schemas & Applications Lecture 5 XML & PHP.

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

Advanced XSLT II. Iteration in XSLT we sometimes wish to apply the same transform to a set of nodes we iterate through a node set the node set is defined.
Advanced XSLT. Branching in XSLT XSLT is functional programming –The program evaluates a function –The function transforms one structure into another.
Advanced XSLT II. Iteration in XSLT we sometimes wish to apply the same transform to a set of nodes we iterate through a node set the node set is defined.
Dr. Alexandra I. Cristea CS 253: Topics in Database Systems: XPath, NameSpaces.
CG0119 Web Database Systems Parsing XML using SimpleXML.
CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT.
What is XML? a meta language that allows you to create and format your own document markups a method for putting structured data into a text file; these.
XML: Extensible Markup Language
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 12 Extensible Stylesheet Language Transformations : XSLT.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
ESDSWG2011 – Semantic Web session Semantic Web Sub-group Session ESDSWG 2011 Meeting – Semantic Web sub-group session Wednesday, November 2, 2011 Norfolk,
An Introduction to XML Based on the W3C XML Recommendations.
UFCEKG-20-2 Data, Schemas & Applications Lecture 6 The Web of Data, API’s & PHP.
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
Lecture 14 XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name.
Extensible Markup Language XML MIS 520 – Database Theory Fall 2001 (Day) Lecture 14.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
Tutorial 11 Creating XML Document
XML Primer. 2 History: SGML vs. HTML vs. XML SGML (1960) XML(1996) HTML(1990) XHTML(2000)
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
PHP with XML Dequan Chen and Narith Kun ---Term Project--- for WSU 2010 Summer Course - CS366 s:
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
Lecture 15 XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name.
XML eXtensible Markup Language by Darrell Payne. Experience Logicon / Sterling Federal C, C++, JavaScript/Jscript, Shell Script, Perl XML Training XML.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
XML CPSC 315 – Programming Studio Fall 2008 Project 3, Lecture 1.
CG0119 Web Database Systems Using XPath to Navigate & Filter XML (via SimpleXML)‏
XML and its applications: 4. Processing XML using PHP.
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
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.
Lecture 2 : Understanding the Document Object Model (DOM) UFCFR Advanced Topics in Web Development II 2014/15 SHAPE Hong Kong.
XML A Single Entity. xml a single entity Objectives Objectives :  understand the data model  describe the XML Document  describe the XML Schema  describe.
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
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.
 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
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
Lecture 14 Extensible Stylesheet Language Transformations : XSLT.
XPath. Why XPath? Common syntax, semantics for [XSLT] [XPointer][XSLT] [XPointer] Used to address parts of an XML document Provides basic facilities for.
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
XPath Aug ’10 – Dec ‘10. XPath   XML Path Language   Technology that allows to select a part or parts of an XML document to process   XPath was.
1 Introduction  Extensible Markup Language (XML) –Uses tags to describe the structure of a document –Simplifies the process of sharing information –Extensible.
An OO schema language for XML SOX W3C Note 30 July 1999.
School of Computing and Information Systems CS 371 Web Application Programming XML and JSON Encoding Data.
Lecture 3 : PHP5-DOM API UFCFR Advanced Topics in Web Development II 2014/15 SHAPE Hong Kong.
XML Basics A brief introduction to XML in general 1XML Basics.
1 Tutorial 11 Creating an XML Document Developing a Document for a Cooking Web Site.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
Unit 10 Schema Data Processing. Key Concepts XML fundamentals XML document format Document declaration XML elements and attributes Parsing Reserved characters.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
1 JAXP & XPATH. Objectives 2  XPath  JAXP Processing of XPath  Workshops.
Introduction to XML XML – Extensible Markup Language.
XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name value pair;
XSLT: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
What is it? –w3c standard for… Navigating through an XML document Filtering & finding information –Includes… Expressions for navigating to parts of an.
Lecture 15 Extensible Stylesheet Language Transformations : XSLT.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
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.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
Unit 4 Representing Web Data: XML
Chapter 7 Representing Web Data: XML
XML and its applications: 4. Processing XML using PHP
Presentation transcript:

UFCEKG-20-2 Data, Schemas & Applications Lecture 5 XML & PHP

Richter Scales on Web 2.0 The Richter Scales FTSE 100

Degree Confluence Twitter Trends Location, Location, Location

Tree structures (with their representation as tree diagrams) are a key data structure which appear in many places in addition to XML o Folder hierarchy o Document Object Model (DOM)DOM o Organisational reporting structures o Paragraph Numbering in a Document o Natural classification of living things - LinnaeusLinnaeus o Dewey Classification of knowledge Dewey o Java Class hierarchy Java Class hierarchy Not all natural structures are pure trees with a single root and only one path from any node to the root Navigating trees

Example XML document Joseph Michael Bloggs Joe Mr 2 Gloucester Road Bristol Avon BS2 4QS XML as nested list

a simple element containing text attribute; attributes provide additional information about an element and consist of a name value pair; the value must be enclosed in a single (‘) or double quote (“) Example XML document deconstructed Joseph Michael Bloggs Joe Mr 2 Gloucester Road Bristol Avon BS2 4QS xml declaration (optional) used by xml processor; this documents conforms to xml version 1 and uses the UTF-8 standard (Unicode optimized for ASCII) root element; every well formed xml document must be enclosed by exactly one root element. empty elements a complex element containing other elements and text a comment; comments must be delimited by the characters as in xhtml

fred Joe Eric ted alice Sample XML XML XML as nested lists

Processing XML files requires a language to support operations like: o reading in a XML file and converting to a internal structure o navigating around the internal structure o creating XML structures XML processing

Syntax for tree navigation. Getting to the node containing the text 'Alice' o XPath: $xml/d/x[2] o Javascript DOM : $xml.getElementsByTagname['d'].0.childNodes[1] (approx) o PHP SimpleXML : $xml->d->x[1] o Java... Tree Navigation

To construct a tree of objects from a string o $xmltree = new SimpleXMLElement($string); PHP : Constructing an XML object tree

In PHP the operator -> is used to reference from an object to its properties. The equivalent operator in Java is "." (dot) and in XPath is "/". In an XML object tree, each element is a property of its parent. If $x is an element o $x->getName() is the name of the element - its tag o $x->y is the sequence of y children - an array even if only one) o $x->y[0] is the first y child o foreach ($x->y as $y) {.. } iterates over the y children o $x->children() is the seqeunce of all $x's children o $x->xpath(...) evaluate an XPath expression PHP : access to child elements

If $x is an element o $x->attributes() is the sequence of x attributes o $x->attributes()->z is the z attribute of x o foreach ($x->attributes() as $att {.. } iterates over attributes of $x PHP : access to attributes

Namespaces in XML comprise o a prefix used in the tag geo:lat, o a uri which identifies that namespace " o a notation for defining the relationship (binding) between the two - a pseudo element attribute usually at document level -e.g. xmlns:geo= Access to elements in a namespace uses the children() function with the namespaceuri as the parameter. By default it gives you all children. PHP : access to namespaces

XML Processing Example (wines.xml) We will make use of the file (wines.xml) in many of the following examples: Preference Cutes de Rhune Rouge This Caves Saint Pierre Prèference Cùtes du Rhùne is an easy drinking and spicy red wine laden with summer fruit flavours crr.jpg Mateus Rose An all time favourite mro.jpg Blossom Hill White Grenache Rose Aromas of red berry, cherry and white pepper. Lush on the palate with lots of berries. Citrus and honeysuckle notes bhro.jpg

<?php $wines = simplexml_load_file('wines.xml'); foreach ($wines->category as $category){ echo " "; echo " Type: ".$category["name"]." "; foreach ($category->product as $product){ echo $product->title. ' '; } echo " "; } ?> Using SimpleXML extension in PHP 5 run the code

Using XPath to search documents Sometimes there is a need to search through a document (e.g. when the exact format or order of the nodes is not known in advance) or when only a small set of nodes need to be found in a very large document. Using the Xpath support built into the SimpleXML extension this is made easy. The basic format of a XPath query takes the form “a/b/c” where a, b, c are nested xml tags of the form. Some common XPath queries are as follows: a : matches any tag named a a/b : matches any tag named b, directly contained in the tag a a/b/.. : matches and returns the tag a instead of b a//b : matches b when it is any descendent of a a[31] : matches the 31st a tag a[last()] : matches the very last a tag : matches any a with an attribute named “ att ” matches any tag called a with an attribute named “ att ” with the value “ val ”

SimpleXML & XPath example <?php $wines = simplexml_load_file('wines.xml'); $category = $wines->xpath('//category'); foreach ($category as $c) { echo " "; echo " Type: {$c['name']} "; $title = $c->xpath('./product/title'); foreach ($title as $t) { echo "{$t} "; } echo " "; } ?> run the code