1 / 9

Mastering XML Traversal: A Comprehensive Guide to XPath Syntax and Filtering

Dive into the intricacies of XML traversal with XPath in this insightful guide. Explore the nine traversal directions: self, child, parent, preceding-sibling, following-sibling, ancestor, descendant, preceding, and following. Learn how to combine commands for effective filtering and manipulation of XML data. This resource covers essential XPath node types, offers practical shortcuts, and discusses the common pitfalls of namespaces, ensuring you approach XML with confidence and precision. Perfect for developers and data analysts seeking to enhance their skills in XML data handling.

jemma
Télécharger la présentation

Mastering XML Traversal: A Comprehensive Guide to XPath Syntax and Filtering

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. Introduction to XPath Lech Rzedzicki , Kode1100 Ltd Stuart Moorhouse, DK

  2. Traversing XML • XML can be traversed in 9 directions: self, child, parent, preceding-sibling, following-sibling, ancestor, descendant, preceding, following, • You can combine/chain commands filter commands • Example: <A><B><C/></B><D/><E/><F><G><H/></G><I/><J><K/><L><M/><N/></L><O/><P/><Q><R/><S/></Q></J><T/><U><V/></U></F><W/><X/><Y><Z/></Y></A>

  3. Example in Xpath

  4. 7 types of Nodes on the tree • Document • Namespaces • Elements • Attributes • Comments • Processing-instructions • Text

  5. Namespaces • Namespaces are N°1 source of problems. • Remember about the default namespace. • Prefix is not a namespace: dita:book≠dita:book • Define the namespaces properly and then you can even use different prefix (but don’t).

  6. Shortcuts • // any descendant • . Current node • * all/any elements • @* all attributes

  7. Combine with RegExp • In OxygenXML Find/Replace window • In Xpath bar • //section[count(descendant::node())=0]/text() +regexp: .* would select the whole text of the lowest level sections in the document

  8. Exercise: sample-dk.xml //section[@metaref] distinct-values(//@metaref/tokenize(.,'\s+')) /book/part[1]/chapter[1]/section[1]/section[1]/section[1]/section[1]/section[2]/para[1]/address[2]/phrase[1] //ancestor::node()[substring-after(@rend,'level_LH')='2']

More Related