XPath - A practical guide

        Arne Blankerts <arne@thephp.cc>, TobiasSchlitt <toby@php.net>

                        ...
Outline



 1 Welcome


 2 Introduction


 3 In details


 4 Quiz


 5 The end




Arne Blankerts, Tobias Schlitt (IPC 200...
Arne Blankerts




         Arne Blankerts <arne@thephp.cc>
         PHP since 1999 (10 years of PHP!)
         Co-Founder...
Tobias Schlitt



         Tobias Schlitt <toby@php.net>
         PHP since 2001
         Freelancing consultant
         ...
Outline



 1 Welcome


 2 Introduction
          Overview
          Basics

 3 In details


 4 Quiz


 5 The end



Arne ...
Overview


  XPath
  Enables you to select information parts from XML documents.

          Traverse the XML tree
        ...
Addressing




          Every XPath expression matches a set of nodes (0..n)
          It encodes an “address” for the se...
Practical




 Let’s dig into the code




Arne Blankerts, Tobias Schlitt (IPC 2009)   XPath - A practical guide   2009-11...
Outline


 1 Welcome


 2 Introduction


 3 In details
          Syntax
          Specialities
          Functions
       ...
Syntax elements




                     / Level seperator
                  // Multi-level seperator
                    ...
Contexts




          Every expression step creates new context
          Next evaluated in context created by previous s...
Navigation




                     / One level down
                  // Any number of levels down
                ../ On...
Practical




 Let’s dig into the code




Arne Blankerts, Tobias Schlitt (IPC 2009)   XPath - A practical guide   2009-11...
Indexing




  Access nodes by position: [2]
  Start index
       Indexing generally 1 based
          Some Internet Explo...
Union




  Union the node sets selected by multiple XPath expressions.




Arne Blankerts, Tobias Schlitt (IPC 2009)   XP...
Practical




 Let’s dig into the code




Arne Blankerts, Tobias Schlitt (IPC 2009)   XPath - A practical guide   2009-11...
Functions
 String                                                  Context
         string-join()                         ...
Axis
  13 dimensions
  Imagine an XML document to be a 13 dimensional space...

                                    Axis  ...
Practical




 Let’s dig into the code




Arne Blankerts, Tobias Schlitt (IPC 2009)   XPath - A practical guide   2009-11...
PHP function integration




          Register PHP callbacks to enhance functionality
          Possible since PHP 5.3.0
...
Practical




 Let’s dig into the code




Arne Blankerts, Tobias Schlitt (IPC 2009)   XPath - A practical guide   2009-11...
Outline



 1 Welcome


 2 Introduction


 3 In details


 4 Quiz


 5 The end




Arne Blankerts, Tobias Schlitt (IPC 200...
Quiz




          //node
          /root/element
          /root/element[1]
          @id
          /root//node/@name
   ...
Quiz




          //node
          /root/element
          /root/element[1]
          @id
          /root//node/@name
   ...
Quiz




          //node
          /root/element
          /root/element[1]
          @id
          /root//node/@name
   ...
Quiz




          //node
          /root/element
          /root/element[1]
          @id
          /root//node/@name
   ...
Quiz




          //node
          /root/element
          /root/element[1]
          @id
          /root//node/@name
   ...
Quiz




          //node
          /root/element
          /root/element[1]
          @id
          /root//node/@name
   ...
Quiz




          //node
          /root/element
          /root/element[1]
          @id
          /root//node/@name
   ...
Outline



 1 Welcome


 2 Introduction


 3 In details


 4 Quiz


 5 The end




Arne Blankerts, Tobias Schlitt (IPC 200...
Q/A




          Are there any questions left?
          Please give us some feedback!




Arne Blankerts, Tobias Schlitt...
The end




          Thanks for being here!
          We hope you enjoyed the session!
          Slides and material
    ...
Upcoming SlideShare
Loading in...5
×

XPath - A practical guide

5,831

Published on

Slides from the XPath tutorial given by Arne Blankerts and me on the IPC 2009. We did a lot of life hacking during the session, so the slides are not that extensive.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,831
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
124
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

XPath - A practical guide

  1. 1. XPath - A practical guide Arne Blankerts <arne@thephp.cc>, TobiasSchlitt <toby@php.net> IPC 2009 2009-11-17 Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 1 / 26
  2. 2. 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
  3. 3. Arne Blankerts Arne Blankerts <arne@thephp.cc> PHP since 1999 (10 years of PHP!) Co-Founder of thePHP.cc ballyhoo. werbeagentur. Open source addicted Inventor and lead developer of fCMS site system Contributor and translator for the PHP manual Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 3 / 26
  4. 4. Tobias Schlitt Tobias Schlitt <toby@php.net> PHP since 2001 Freelancing consultant Qualified IT Specialist Studying CS at TU Dortmund (finishing 2010) OSS addicted PHP eZ Components PHPUnit Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 4 / 26
  5. 5. Outline 1 Welcome 2 Introduction Overview Basics 3 In details 4 Quiz 5 The end Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 5 / 26
  6. 6. 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
  7. 7. 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
  8. 8. Practical Let’s dig into the code Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 8 / 26
  9. 9. Outline 1 Welcome 2 Introduction 3 In details Syntax Specialities Functions Axis PHP function integration 4 Quiz 5 The end Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 9 / 26
  10. 10. 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
  11. 11. 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
  12. 12. 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
  13. 13. Practical Let’s dig into the code Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 13 / 26
  14. 14. 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
  15. 15. 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
  16. 16. Practical Let’s dig into the code Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 16 / 26
  17. 17. Functions String Context string-join() position() substring() last() starts-with() Aggregate contains() count() string-length() min() / max() Math Node round() local-name() floor() Logic not() true() Function overview An overview on all functions can be found on http://www.w3.org/TR/xpath-functions/ Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 17 / 26
  18. 18. 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
  19. 19. Practical Let’s dig into the code Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 19 / 26
  20. 20. 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
  21. 21. Practical Let’s dig into the code Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 21 / 26
  22. 22. 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
  23. 23. 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
  24. 24. 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
  25. 25. 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
  26. 26. 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
  27. 27. 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
  28. 28. 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
  29. 29. 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
  30. 30. 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
  31. 31. 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
  32. 32. The end Thanks for being here! We hope you enjoyed the session! Slides and material Delivered by Software & Support http://schlitt.info/opensource On slideshare: http://www.slideshare.net/tobyS Contact us: Arne Blankerts <arne@thephp.cc> Tobias Schlitt <toby@php.net> Please rate our talk at: http://joind.in/1042 Arne Blankerts, Tobias Schlitt (IPC 2009) XPath - A practical guide 2009-11-17 26 / 26
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×