Edgewall Software

Changes between Version 4 and Version 5 of MarkupPath


Ignore:
Timestamp:
Sep 8, 2006, 10:11:18 AM (18 years ago)
Author:
cmlenz
Comment:

Move to reStructuredText

Legend:

Unmodified
Added
Removed
Modified
  • MarkupPath

    v4 v5  
    1 = Using XPath in Markup =
     1{{{
     2#!rst
     3=====================
     4Using XPath in Markup
     5=====================
    26
    3 Markup provides basic [http://www.w3.org/TR/xpath XPath] support for matching and querying event streams.
     7Markup provides basic XPath_ support for matching and querying event streams.
    48
    5 == Limitations ==
     9.. _xpath: http://www.w3.org/TR/xpath
    610
    7 Due to the streaming nature of the processing model, Markup uses only a subset of the [http://www.w3.org/TR/xpath XPath 1.0] language.
     11
     12.. contents:: Contents
     13   :depth: 2
     14.. sectnum::
     15
     16
     17-----------
     18Limitations
     19-----------
     20
     21Due to the streaming nature of the processing model, Markup uses only a subset
     22of the `XPath 1.0`_ language.
     23
     24.. _`XPath 1.0`: http://www.w3.org/TR/xpath
    825
    926In particular, only the following axes are supported:
    10  * `attribute`
    11  * `child`
    12  * `descendant`
    13  * `descendant-or-self`
    14  * `self`
    1527
    16 This means you can't use the `parent`, ancestor, or sibling axes in Markup (the `namespace` axis isn't supported either, but what you'd ever need that for I don't know). Basically, any path expression that would require buffering of the stream is not supported.
     28* ``attribute``
     29* ``child``
     30* ``descendant``
     31* ``descendant-or-self``
     32* ``self``
    1733
    18 Predicates are of course supported, but Path expressions ''inside'' predicates are restricted to attribute lookups (again due to the lack of buffering).
     34This means you can't use the ``parent``, ancestor, or sibling axes in Markup
     35(the ``namespace`` axis isn't supported either, but what you'd ever need that
     36for I don't know). Basically, any path expression that would require buffering
     37of the stream is not supported.
    1938
    20 Most of the XPath functions and operators are supported, however they (currently) only work inside predicates. The following functions are '''not''' supported:
     39Predicates are of course supported, but Path expressions *inside* predicates
     40are restricted to attribute lookups (again due to the lack of buffering).
    2141
    22  * `count()`
    23  * `id()`
    24  * `lang()`
    25  * `last()`
    26  * `position()`
    27  * `string()`
    28  * `sum()`
     42Most of the XPath functions and operators are supported, however they
     43(currently) only work inside predicates. The following functions are **not**
     44supported:
    2945
    30 The mathematical operators (`+`, `-`, `*`, `div`, and `mod`) are not yet supported, whereas the various comparison and logical operators should work as expected.
     46* ``count()``
     47* ``id()``
     48* ``lang()``
     49* ``last()``
     50* ``position()``
     51* ``string()``
     52* ``sum()``
    3153
    32 You can also use XPath variable references (`$var`) inside predicates.
     54The mathematical operators (``+``, ``-``, ``*``, ``div``, and ``mod``) are not
     55yet supported, whereas the various comparison and logical operators should work
     56as expected.
    3357
    34 == Querying Streams ==
     58You can also use XPath variable references (``$var``) inside predicates.
    3559
    36 {{{
    37 #!python
    38 from markup.input import XML
    3960
    40 doc = XML('''<doc>
    41  <items count="2">
    42       <item status="new">
    43         <summary>Foo</summary>
    44       </item>
    45       <item status="closed">
    46         <summary>Bar</summary>
    47       </item>
    48   </items>
    49 </doc>''')
    50 print doc.select('items/item[@status="closed"]/summary/text()')
     61----------------
     62Querying Streams
     63----------------
     64
     65::
     66
     67  from markup.input import XML
     68
     69  doc = XML('''<doc>
     70   <items count="2">
     71        <item status="new">
     72          <summary>Foo</summary>
     73        </item>
     74        <item status="closed">
     75          <summary>Bar</summary>
     76        </item>
     77    </items>
     78  </doc>''')
     79  print doc.select('items/item[@status="closed"]/summary/text()')
     80
     81This would result in the following output::
     82
     83  Bar
    5184}}}
    52 
    53 This would result in the following output:
    54 
    55 {{{
    56 #!xml
    57 Bar
    58 }}}
    59 
    60 == Matching in Templates ==
    61 
    62 See MarkupTemplates#py:match
    6385
    6486----