28
Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Embed Size (px)

Citation preview

Page 1: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Date : 3/3/2010

Web Technology SolutionsClass: Application Syndication: Parse and Publish RSS & XML Data

Page 2: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Tonight

✤ Introduction to XML

✤ Creating XML, RSS, and JSON with PHP

✤ using simpleXML for XML\RSSLab

Page 3: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Lab Preview

✤ Application Development

✤ Registration Feature

✤ Login\Logout

✤ Maintain State

✤ Admin CRUD for Survey

✤ Publish XML and RSS

Page 4: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Lab Preview

✤ Application Development:

✤ Adding XML and RSS

✤ Publish an RSS feed of your survey responses

✤ Publish an XML dump of your survey responses

✤ You will implement an ECO to provide XML publication of a table in your database. Provide a URL of feed.

Page 5: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Final Project Review

✤ Final Project - Web App (link)

✤ registration feature (week 6)

✤ login logout (week 7)

✤ admin ability to create\read\update\delete (CRUD) (week 4-5)

✤ Maintain State throughout app (cookies\sessions) (week 7)

✤ XML and RSS feeds (week 8)

✤ Valid XHTML and CSS design

Page 6: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Web Apps

✤ Problem with apps:

✤ Data stored in other systems can’t be shared easily.

✤ Data is in different formats

✤ Data has no meaning to other systems, just its own native system.

Page 7: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Web Apps

✤ Goals:

✤ Share information across multiple environments

✤ Open, flexible language to share data

✤ Provide schematic meaning to data elements

Page 8: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Solution:XML

Page 9: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Intro to XML

✤ Markup language for documents containing structured information.

✤ Extensible Markup Language (akin to HTML)

✤ Supported by W3C as a standard

✤ Provides known structure and relevant meaning to that data structure.

✤ Widely used (iTunes, e.g.)

✤ Perfect for PHP developers to share data.

Page 10: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Terms of XML

✤ Meta: literally “provides meaning”.

✤ Schema: A logical organized structure of data.

✤ Tags: Elements in XML that are data containers

✤ Attributes: Extend meaning of a tag

✤ Serialize: saving or storing data

✤ Nodes: a DOM structure of a data object (tree)

Page 11: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

XML Sample

✤ Consider this example:

<?xml version=”1.0”?>

<product barcode=”2323423”>

<maker>Smithson</maker>

<name>Apex DVD Player 1.2</name>

<quantity>3</quantity>

<size>33cm</size>

<color>black</color>

</product>

Page 12: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

XML Syntax Structure

✤ Consider this example:

<?xml version=”1.0”?> // XML Definition (version)

<product barcode=”2323423”>

<maker>Smithson</maker>

<name>Apex DVD Player 1.2</name>

<quantity>3</quantity>

<size>33cm</size>

<color>black</color>

</product>

Page 13: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

XML Syntax Structure

✤ Consider this example:

<?xml version=”1.0”?> // XML Definition (version)

<product barcode=”2323423”> // Extending Tagging System (user defined markup adds meaning)

<maker>Smithson</maker>

<name>Apex DVD Player 1.2</name>

<quantity>3</quantity>

<size>33cm</size>

<color>black</color>

</product>

Page 14: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

XML Syntax Structure

✤ Consider this example:

<?xml version=”1.0”?> // XML Definition (version)

<product barcode=”2323423”> // Extending Tagging System (user defined markup adds meaning)

<maker>Smithson</maker> //Tags are created and defined by the developer (XSD) XML Schema

<name>Apex DVD Player 1.2</name>

<quantity>3</quantity>

<size>33cm</size>

<color>black</color>

</product>

Page 15: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

XML Syntax Structure

✤ Consider this example:

<?xml version=”1.0”?> // XML Definition (version)

<product barcode=”2323423”> // Extending Tagging System (user defined markup adds meaning)

<maker>Smithson</maker> //Tags are created and defined by the developer (XSD) XML Schema

<name>Apex DVD Player 1.2</name> //Tags contain strictly strings

<quantity>3</quantity> //requires: start tag <quantity> and end tag </quantity>

<size>33cm</size> // string value is found between the tags.

<color hexvalue=”0x000000”>black</color> //tags can have attributes

</product>

Page 16: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Nodes in XML

✤ The Node:

✤ Contains all relevant data about an element.

✤ For example: <product>, which contains all the data for that individual product.

✤ This node has “childnodes”, such as <color>

✤ Data can be a string (but more...)

Page 17: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

CDATA in XML

✤ CDATA

✤ Data can hold more complex data, like HTML, using CDATA.

✤ Tells the node to contain “raw character data”, not markup.

✤ <![CDATA[

✤ ]]>

✤ Good for containing html, JS, etc, as it will not be treated as plain string data.

Page 18: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Create XML with PHP

✤ fopen() - allows you to open a document on the filesystem. // resource

✤ you can $file= fopen("presidents.xml", "w"); // note safe_mode , open_basedir

✤ read only (r)

✤ read and write(r+)

✤ write only(w)

✤ write and create(w+)

✤ write to end of file (a)

✤ write to end and create (a+)

✤ permissions are an issue! Try chmod to 777 to start and throttle back.

Page 19: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Create XML with PHP

✤ fwrite()

✤ Write to the resource you were using.

✤ Allows you to complete the write to the file system

✤ will return the bytes written if successful.

✤ Be aware of permissions! chmod 777 to start and go lower as needed.

Page 20: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Create XML with PHP

✤ fclose()

✤ closes the current resource.

✤ returns boolean. worth checking!

Page 21: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

XML Example

Page 22: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Create RSS with PHP

✤ Stands for “Real Simple Syndication”

✤ great for sharing or syndicating your content to outside systems

✤ commonly only holds “some recent data”

✤ natively uses XML as a transport

✤ Has several standardized formats.

✤ We’ll use RSS 2.0, common usage.

Page 23: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Create RSS with PHP

✤ RSS has a defined format:

✤ A Channel which allows to add meta about what your syndicating

✤ Should Contain a title, link, and description, (optional date, language,etc)

✤ RSS should have a defined tabbed structure

✤ Related Links: often found on blogs to send a person to the correct page to get more details.

Page 24: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Create RSS with PHP

✤ Browsers “sniff” for RSS feeds on a site

✤ You let the browser know you’re publishing RSS by embedding a meta data tag:

✤ <link rel="alternate" type="application/rss+xml" title="RSS" href="/pathto/rss.xml" />

Page 25: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

RSS Example

Page 26: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

SimpleXML

✤ Simple XML is PHP5’s long-awaited class that allows PHP developers to easily and effectively parse XML data!

✤ Simple to Use (its in the name)

✤ Lets see it in action.

Page 27: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

xPath

✤ What is xPath and why do I care?

✤ XSLT Standard by the W3C

✤ xPath is a syntax for finding information in XML documents

✤ Can find values in nodes or attributes

✤ xPath is part of SimpleXML

✤ Learn more about it!

Page 28: Date : 3/3/2010 Web Technology Solutions Class: Application Syndication: Parse and Publish RSS & XML Data

Lab & Next Week

✤ Lab

✤ implement xml\rss in app

✤ working session for final

✤ Reading: Chapter 13

See you Sunday!