Download - XPath - A practical guide
![Page 1: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/1.jpg)
XPath - A practical guide
Arne Blankerts <[email protected]>, TobiasSchlitt <[email protected]>
IPC 2009
2009-11-17
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 1 / 26
![Page 2: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/2.jpg)
Outline
1 Welcome
2 Introduction
3 In details
4 Quiz
5 The end
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 2 / 26
![Page 3: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/3.jpg)
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) XPath - A practical guide 2009-11-17 3 / 26
![Page 4: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/4.jpg)
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) XPath - A practical guide 2009-11-17 4 / 26
![Page 5: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/5.jpg)
Outline
1 Welcome
2 IntroductionOverviewBasics
3 In details
4 Quiz
5 The end
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 5 / 26
![Page 6: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/6.jpg)
Overview
XPath
Enables you to select information parts from XML documents.
Traverse the XML tree
Select XML nodes
W3C recommendation
Version 1: November 1999
Version 2: January 2007
Fields of application
XSLT (XML Stylesheet Language Transformations)Fetching XML nodes within programming languages
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 6 / 26
![Page 7: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/7.jpg)
Addressing
Every XPath expression matches a set of nodes (0..n)
It encodes an “address” for the selected nodes
Simple XPath expressions look similar to Unix file system addresses
Absolute vs. relative addressing
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 7 / 26
![Page 8: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/8.jpg)
Practical
Let’s dig into the code
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 8 / 26
![Page 9: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/9.jpg)
Outline
1 Welcome
2 Introduction
3 In detailsSyntaxSpecialitiesFunctionsAxisPHP function integration
4 Quiz
5 The end
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 9 / 26
![Page 10: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/10.jpg)
Syntax elements
/ Level seperator
// Multi-level seperator
* Wildcard
@ Attribute prefix
@* Attribute wildcard
[...] Filter / condition
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 10 / 26
![Page 11: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/11.jpg)
Contexts
Every expression step creates new context
Next evaluated in context created by previous step
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 11 / 26
![Page 12: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/12.jpg)
Navigation
/ One level down
// Any number of levels down
../ One level up
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 12 / 26
![Page 13: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/13.jpg)
Practical
Let’s dig into the code
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 13 / 26
![Page 14: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/14.jpg)
Indexing
Access nodes by position: [2]
Start index
Indexing generally 1 based
Some Internet Explorer versions start with 0
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 14 / 26
![Page 15: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/15.jpg)
Union
Union the node sets selected by multiple XPath expressions.
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 15 / 26
![Page 16: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/16.jpg)
Practical
Let’s dig into the code
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 16 / 26
![Page 17: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/17.jpg)
Functions
String
string-join()
substring()
starts-with()
contains()
string-length()
Math
round()
floor()
Context
position()
last()
Aggregate
count()
min() / max()
Node
local-name()
Logic
not()
true()
Function overview
An overview on all functions can be found onhttp://www.w3.org/TR/xpath-functions/
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 17 / 26
![Page 18: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/18.jpg)
Axis
13 dimensions
Imagine an XML document to be a 13 dimensional space...
Axis Shortcut
ancestor
ancestor-or-self
attribute @child -
descendant
descendant-or-self //following
following-sibling
namespace
parent ..preceding
preceding-sibling
self .
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 18 / 26
![Page 19: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/19.jpg)
Practical
Let’s dig into the code
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 19 / 26
![Page 20: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/20.jpg)
PHP function integration
Register PHP callbacks to enhance functionality
Possible since PHP 5.3.0
Works with functions and static methods
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 20 / 26
![Page 21: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/21.jpg)
Practical
Let’s dig into the code
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 21 / 26
![Page 22: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/22.jpg)
Outline
1 Welcome
2 Introduction
3 In details
4 Quiz
5 The end
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 22 / 26
![Page 23: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/23.jpg)
Quiz
//node
/root/element
/root/element[1]
@id
/root//node/@name
/root/element[@name = ’php’]/@*.
./some/*[@class=’tek’]/@id
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 23 / 26
![Page 24: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/24.jpg)
Quiz
//node
/root/element
/root/element[1]
@id
/root//node/@name
/root/element[@name = ’php’]/@*.
./some/*[@class=’tek’]/@id
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 23 / 26
![Page 25: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/25.jpg)
Quiz
//node
/root/element
/root/element[1]
@id
/root//node/@name
/root/element[@name = ’php’]/@*.
./some/*[@class=’tek’]/@id
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 23 / 26
![Page 26: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/26.jpg)
Quiz
//node
/root/element
/root/element[1]
@id
/root//node/@name
/root/element[@name = ’php’]/@*.
./some/*[@class=’tek’]/@id
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 23 / 26
![Page 27: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/27.jpg)
Quiz
//node
/root/element
/root/element[1]
@id
/root//node/@name
/root/element[@name = ’php’]/@*.
./some/*[@class=’tek’]/@id
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 23 / 26
![Page 28: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/28.jpg)
Quiz
//node
/root/element
/root/element[1]
@id
/root//node/@name
/root/element[@name = ’php’]/@*.
./some/*[@class=’tek’]/@id
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 23 / 26
![Page 29: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/29.jpg)
Quiz
//node
/root/element
/root/element[1]
@id
/root//node/@name
/root/element[@name = ’php’]/@*.
./some/*[@class=’tek’]/@id
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 23 / 26
![Page 30: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/30.jpg)
Outline
1 Welcome
2 Introduction
3 In details
4 Quiz
5 The end
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 24 / 26
![Page 31: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/31.jpg)
Q/A
Are there any questions left?
Please give us some feedback!
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 25 / 26
![Page 32: XPath - A practical guide](https://reader033.vdocument.in/reader033/viewer/2022052619/555a0063d8b42aa8098b4e20/html5/thumbnails/32.jpg)
The end
Thanks for being here!
We hope you enjoyed the session!
Slides and material
Delivered by Software & Supporthttp://schlitt.info/opensourceOn slideshare: http://www.slideshare.net/tobyS
Contact us:
Arne Blankerts <[email protected]>Tobias Schlitt <[email protected]>
Please rate our talk at: http://joind.in/1042
Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 26 / 26