1 / 88

An Introduction to XML and Web Technologies The XPath Language

An Introduction to XML and Web Technologies The XPath Language. Anders Møller & Michael I. Schwartzbach  2006 Addison-Wesley. Messages. Exam fixed at January 6, 2010 Thank you for the feedback. ... need more, though. Objectives. Location steps and paths Typical locations paths

oceana
Télécharger la présentation

An Introduction to XML and Web Technologies The XPath Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An Introduction to XML and Web TechnologiesThe XPath Language Anders Møller & Michael I. Schwartzbach  2006 Addison-Wesley

  2. Messages • Exam fixed at January 6, 2010 • Thank you for the feedback. • ... need more, though. An Introduction to XML and Web Technologies

  3. Objectives • Location steps and paths • Typical locations paths • Abbreviations • General expressions An Introduction to XML and Web Technologies

  4. Exercise: XPath 90s

  5. “Let’s get lost” Location paths An Introduction to XML and Web Technologies

  6. XPath Expressions • Flexible notation for navigating around trees • A basic technology that is widely used • uniqueness and scope in XML Schema • pattern matching an selection in XSLT • relations in XLink and XPointer • computations on values in XSLT and XQuery An Introduction to XML and Web Technologies

  7. Location Paths • A location path evaluates to a sequence of nodes • The sequence is sorted in document order • The sequence will never contain duplicates An Introduction to XML and Web Technologies

  8. Locations Steps • Thelocation path is a sequence of steps • A location step consists of • an axis • a nodetest • some predicates axis :: nodetest [Exp1] [Exp2] … An Introduction to XML and Web Technologies

  9. In 45 secondsfind axis/node test/predicatesin the expression below / child::players/ child::player[attribute::handicap<4]

  10. Evaluating a Location Path • A step maps a context node into a sequence • This also maps sequences to sequences • each node is used as context node • and is replaced with the result of applying the step • The path then applies each step in turn An Introduction to XML and Web Technologies

  11. An Example A B B C C D E F C E F F F E E F F An Introduction to XML and Web Technologies

  12. An Example A B B C C D E F C E F F F E E F F Context node An Introduction to XML and Web Technologies

  13. An Example A B B C C D E F C E F F F E E F F descendant::C An Introduction to XML and Web Technologies

  14. An Example A B B C C D E F C E F F F E E F F descendant::C/child::E An Introduction to XML and Web Technologies

  15. An Example A B B C C D E F C E F F F E E F F descendant::C/child::E/child::F An Introduction to XML and Web Technologies

  16. Exercise: Location Path Evaluation 90s

  17. Contexts • The context of an XPath evaluation consists of • a context node (a node in an XML tree) • a context position and size (two nonnegative integers) • a set of variable bindings • a function library • a set of namespace declarations • The application determines the initial context • If the path starts with ‘/’ then • the initial context node is the root • the initial position and size are 1 An Introduction to XML and Web Technologies

  18. Axes • An axis is a sequence of nodes • The axis is evaluated relative to the context node • XPath supports 12 different axes • child • descendant • parent • ancestor • following-sibling • preceding-sibling • attribute • following • preceding • self • descendant-or-self • ancestor-or-self An Introduction to XML and Web Technologies

  19. Axis Directions • Each axis has a direction • Forwards means document order: • child, descendant, following-sibling, following, self, descendant-or-self • Backwards means reverse document order: • parent, ancestor, preceding-sibling, preceding • Stable but depends on the implementation: • attribute An Introduction to XML and Web Technologies

  20. The parent Axis An Introduction to XML and Web Technologies

  21. The parent Axis An Introduction to XML and Web Technologies

  22. The child Axis An Introduction to XML and Web Technologies

  23. The child Axis An Introduction to XML and Web Technologies

  24. The descendant Axis An Introduction to XML and Web Technologies

  25. The descendant Axis An Introduction to XML and Web Technologies

  26. The ancestor Axis An Introduction to XML and Web Technologies

  27. The ancestor Axis An Introduction to XML and Web Technologies

  28. The following-sibling Axis An Introduction to XML and Web Technologies

  29. The following-sibling Axis An Introduction to XML and Web Technologies

  30. The preceding-sibling Axis An Introduction to XML and Web Technologies

  31. The preceding-sibling Axis An Introduction to XML and Web Technologies

  32. The following Axis An Introduction to XML and Web Technologies

  33. The following Axis An Introduction to XML and Web Technologies

  34. The preceding Axis An Introduction to XML and Web Technologies

  35. The preceding Axis An Introduction to XML and Web Technologies

  36. Exercise: Axis in XML 90s

  37. Node Tests • text() • comment() • processing-instruction() • node() • * • QName • *:NCName • NCName:* An Introduction to XML and Web Technologies

  38. Predicates • General XPath expressions • Evaluated with the current node as context • Result is coerced into a boolean • a number yields true if it equals the context position • a string yields true if it is not empty • a sequence yields true if it is not empty An Introduction to XML and Web Technologies

  39. Exercise: Node tests and Predicates 120s

  40. Abbreviations /child::rcp:collection/child::rcp:recipe /child::rcp:ingredient /rcp:collection/rcp:recipe/rcp:ingredient /child::rcp:collection/child::rcp:recipe /child::rcp:ingredient/attribute::amount /rcp:collection/rcp:recipe/rcp:ingredient/@amount /descendant-or-self::node()/ // self::node() . parent::node() .. An Introduction to XML and Web Technologies

  41. Exercise: Abbreviations 90s

  42. “Computare!” General expressions An Introduction to XML and Web Technologies

  43. General Expressions • Every expression evaluates to a sequence of • atomic values • nodes • Atomic values may be • numbers • booleans • Unicode strings • datatypes defined in XML Schema • Nodes have identity An Introduction to XML and Web Technologies

  44. Atomization • A sequence may be atomized • This results in a sequence of atomic values • For element nodes this is the concatenation of all descendant text nodes • For other nodes this is the obvious string An Introduction to XML and Web Technologies

  45. Literal Expressions 42 3.1415 6.022E23 ’XPath is a lot of fun’ ”XPath is a lot of fun” ’The cat said ”Meow!”’ ”The cat said ””Meow!””” ”XPath is just so much fun” An Introduction to XML and Web Technologies

  46. Arithmetic Expressions • +, -, *, div, idiv, mod • Operators are generalized to sequences • if any argument is empty, the result is empty • if all argument are singleton sequences of numbers, the operation is performed • otherwise, a runtime error occurs An Introduction to XML and Web Technologies

  47. Write an XPath expression computing6*8-7+1 30s

  48. Variable References $foo $bar:foo • $foo-17 refers to the variable ”foo-17” • Possible fixes: ($foo)-17, $foo -17, $foo+-17 An Introduction to XML and Web Technologies

  49. Sequence Expressions • The ’,’ operator concatenates sequences • Integer ranges are constructed with ’to’ • Operators: union, intersect, except • Sequences are always flattened • These expression give the same result: (1,(2,3,4),((5)),(),(((6,7),8,9)) 1 to 9 1,2,3,4,5,6,7,8,9 An Introduction to XML and Web Technologies

  50. Path Expressions • Locations paths are expressions • The may start from arbitrary sequences • evaluate the path for each node • use the given node as context node • context position and size are taken from the sequence • the results are combined in document order An Introduction to XML and Web Technologies

More Related