27
Professional XML with PHP Arne Blankerts <[email protected]>, TobiasSchlitt <[email protected]> IPC 2009 2009-11-15 Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 1 / 26

Professional XML with PHP

Embed Size (px)

DESCRIPTION

Slides from our XML workshop on the International PHP Conference 2009 in Karlsruhe. Not that much information in here, since we did a lot of live stuff. But hopefully still valueable.

Citation preview

Page 1: Professional XML with PHP

Professional XML with PHP

Arne Blankerts <[email protected]>, TobiasSchlitt <[email protected]>

IPC 2009

2009-11-15

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 1 / 26

Page 2: Professional XML with PHP

Outline

1 OverviewWelcomeOverview

2 XML

3 XML in PHP

4 Open part

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 2 / 26

Page 3: Professional XML with PHP

Arne Blankerts

Arne Blankerts <[email protected]>

PHP since 1999 (10 years of PHP!)

Co-Founder of thePHP.cc

ballyhoo. werbeagentur.

Open source addicted

Inventor and lead developer of fCMS sitesystemContributor and translator for the PHP manual

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 3 / 26

Page 4: Professional XML with PHP

Tobias Schlitt

Tobias Schlitt <[email protected]>

PHP since 2001

Freelancing consultant

Qualified IT Specialist

Studying CS at TU Dortmund(finishing 2010)

OSS addicted

PHPeZ ComponentsPHPUnit

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 4 / 26

Page 5: Professional XML with PHP

So, what about you?

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 5 / 26

Page 6: Professional XML with PHP

Conferences are about contacts

That is why both begin with con. . .

Who are you?

What is your business?

What is your intention behind coming to IPC?

What do you expect from this workshop?

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 6 / 26

Page 7: Professional XML with PHP

What can you expect?

Workshop

Introduction to XML

Working on XML data withPHP

Practical tips and tricks

Interactive: What would you liketo know?

XPath

Tuesday, 13:45 - 14:45

XPath in depth

Validating XML

Tuesday, 15:15 - 16:15

DTD, XML Schema andRelaxNG

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 7 / 26

Page 8: Professional XML with PHP

Rules for this workshop

Allways Stick to your place!

Never ask! Repeat: I will not ask anything!

We are not here to show you anything useful!

The only correct solution is told by us!

Do not give feedback on http://joind.in/1041

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 8 / 26

Page 9: Professional XML with PHP

Rules for this workshop

Allways Stick to your place!

Never ask! Repeat: I will not ask anything!

We are not here to show you anything useful!

The only correct solution is told by us!

Do not give feedback on http://joind.in/1041

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 8 / 26

Page 10: Professional XML with PHP

Outline

1 Overview

2 XMLOverviewGet into code. . .

3 XML in PHP

4 Open part

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 9 / 26

Page 11: Professional XML with PHP

What is XML?

General specification for creating markup languages

Data exchange between computer systems

System independentHuman readableMost used on the webSuccessor of SGML

W3C recommendation

1.0 1998 (last update 2008-11-26)1.1 2004 (last update 2006-08-16)

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 10 / 26

Page 12: Professional XML with PHP

XML languages by example

XHTML XML variant of the popular HTML

RSS Really Simply SyndicationProvide news / updates / ... of websitesRead by special clientsAggregation on portals / planets

SVG Scalable Vector GraphicsDescribe vector graphics in XMLPotentially interactive / animated(via ECMAScript)

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 11 / 26

Page 13: Professional XML with PHP

Related technologies - Schemas

Schema

A schema defines the structure XML instance documents.

XMLSchema Written in XMLW3C recommendationPopular

RelaxNG 2 syntax variants

XML basedShort plain text based

OASIS / ISO standardPopular

DTD Plain textW3C recommendationDeprecated

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 12 / 26

Page 14: Professional XML with PHP

Related technologies - Querying

Query

A query extracts a sub-set of information from a data source.

XPath W3C recommendationNavigation in XML documentsmore on that later...

XQuery Functional programming languageAllows complex queries

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 13 / 26

Page 15: Professional XML with PHP

Practical

Let’s get into the code

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 14 / 26

Page 16: Professional XML with PHP

Outline

1 Overview

2 XML

3 XML in PHPDOMXMLReader/-Writer

4 Open part

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 15 / 26

Page 17: Professional XML with PHP

Overview

XML APIs

PHP has quite some XML APIs.

The most important are:

DOMXMLReader / XMLWriterSimpleXML

Deprecated are:

DOM XMLXML Parser

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 16 / 26

Page 18: Professional XML with PHP

Overview - DOM

Document Object Model

Standardized API to access XML tree

W3C recommendationLevel 1 in 1999Currently: Level 3 (2004)

Available in many languages

CJavaPerlPython...

Represents XML nodes as objects

Loads full XML tree into memory

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 17 / 26

Page 19: Professional XML with PHP

Overview - XMLReader/-Writer

Popular approach to access XML data

Similar implementations available in

JavaC#

Pull / push based

Does not load XML fully into memory

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 18 / 26

Page 20: Professional XML with PHP

Overview - SimpleXml

Very simple access to XML data

Unique (?) to PHP

Represents XML structures as objects

Initial implementation hackish

Loads full XML tree into memory

You don’t want to use SimpleXML, seriously!

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 19 / 26

Page 21: Professional XML with PHP

APIs compared

DOM XMLReader/-Writer SimpleXML

Read ? ? •Write ? ? ◦Manipulate ? • •Full control ? ? -

Namespaces ? ? ◦XPath ? - ?

Validate DTD DTD -Schema SchemaRelaxNG RelaxNG

Comfort • ◦ ?

? Fully supported

• Supported but not nice

◦ Poorly supported

- Not supported at all

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 20 / 26

Page 22: Professional XML with PHP

Practical

Let’s get into the code

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 21 / 26

Page 23: Professional XML with PHP

Practical

Let’s get into the code

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 22 / 26

Page 24: Professional XML with PHP

Outline

1 Overview

2 XML

3 XML in PHP

4 Open part

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 23 / 26

Page 25: Professional XML with PHP

What would you like to do?

Discuss a particular problem?

See a special XML technique in PHP?

Get to know related techniques?

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 24 / 26

Page 26: Professional XML with PHP

Q/A

Are there any questions left?

Please give us some feedback!

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 25 / 26

Page 27: Professional XML with PHP

The end

We hope you enjoyed the workshop!

Slides and material

Delivered by Software & Supporthttp://schlitt.info/opensourceOn Slideshare (http://slideshare.net)

Contact us:

Arne Blankerts <[email protected]>Tobias Schlitt <[email protected]>

Give us feedback on http://joind.in/1041

Arne Blankerts, Tobias Schlitt (IPC 2009) Professional XML with PHP 2009-11-15 26 / 26