1 / 6

Designing Streamable XPath Expressions

Designing Streamable XPath Expressions. Roger L. Costello January 5, 2014. Acknowledgement. The example shown in the following slides comes from the XSLT 3.0 specification. Count the <head> elements.

Download Presentation

Designing Streamable XPath Expressions

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. Designing Streamable XPath Expressions Roger L. CostelloJanuary 5, 2014

  2. Acknowledgement • The example shown in the following slides comes from the XSLT 3.0 specification.

  3. Count the <head> elements • Suppose an XML document contains a bunch of <section> elements. Every <section> element has a child <head> element. You are to create an XPath expression to count the <head> elements that are within the <section> elements. • A <section> element may contain a child <section> element (in addition to its child <head> element). • Here is a sample XML document: <section> <section> <head>…</head> </section> <head>…</head> </section> count(xpath) should return 2. • You are to design the XPath so that it can be used in a streaming program: you are to design a streamable XPath expression!

  4. Not a streamable XPath expression • This XPath is not streamable: count(//section/head) • Let’s see why. • Consider our sample XML document: <section> <section> <head>…</head> </section> <head>…</head> </section> This is the first section element that is fetched. Its head element is down here To fetch the second section element the XSLT processor would have to back up, which is not allowed in streaming. Therefore, this XPath expression is not streamable: //section/head

  5. Streamable XPath expression • A rule of streaming is that you can always access ancestors. • So, to make the XPath expression viable for streaming, find each <head> element that has a parent <section> element: count(/descendant::head[parent::section]) <section> <section> <head>…</head> </section> <head>…</head> </section> This is the first headelement that is fetched. It has a parent sectionelement. Therefore, this XPath expression is streamable: /descendant::head[parent::section]

  6. Issues in streaming • A streaming processor always moves forward, it can never back up. So if your program contains an XPath expression which would require the processor to back up, your program is not streamable. • As a streaming processor descends the input document’s XML tree, it keeps a record of nodes it has visited. Thus, your program can reference ancestors.

More Related