Changes between Version 4 and Version 5 of MarkupPath
- Timestamp:
- Sep 8, 2006, 10:11:18 AM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
MarkupPath
v4 v5 1 = Using XPath in Markup = 1 {{{ 2 #!rst 3 ===================== 4 Using XPath in Markup 5 ===================== 2 6 3 Markup provides basic [http://www.w3.org/TR/xpath XPath]support for matching and querying event streams.7 Markup provides basic XPath_ support for matching and querying event streams. 4 8 5 == Limitations == 9 .. _xpath: http://www.w3.org/TR/xpath 6 10 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 ----------- 18 Limitations 19 ----------- 20 21 Due to the streaming nature of the processing model, Markup uses only a subset 22 of the `XPath 1.0`_ language. 23 24 .. _`XPath 1.0`: http://www.w3.org/TR/xpath 8 25 9 26 In particular, only the following axes are supported: 10 * `attribute`11 * `child`12 * `descendant`13 * `descendant-or-self`14 * `self`15 27 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`` 17 33 18 Predicates are of course supported, but Path expressions ''inside'' predicates are restricted to attribute lookups (again due to the lack of buffering). 34 This 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 36 for I don't know). Basically, any path expression that would require buffering 37 of the stream is not supported. 19 38 20 Most of the XPath functions and operators are supported, however they (currently) only work inside predicates. The following functions are '''not''' supported: 39 Predicates are of course supported, but Path expressions *inside* predicates 40 are restricted to attribute lookups (again due to the lack of buffering). 21 41 22 * `count()` 23 * `id()` 24 * `lang()` 25 * `last()` 26 * `position()` 27 * `string()` 28 * `sum()` 42 Most of the XPath functions and operators are supported, however they 43 (currently) only work inside predicates. The following functions are **not** 44 supported: 29 45 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()`` 31 53 32 You can also use XPath variable references (`$var`) inside predicates. 54 The mathematical operators (``+``, ``-``, ``*``, ``div``, and ``mod``) are not 55 yet supported, whereas the various comparison and logical operators should work 56 as expected. 33 57 34 == Querying Streams == 58 You can also use XPath variable references (``$var``) inside predicates. 35 59 36 {{{37 #!python38 from markup.input import XML39 60 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 ---------------- 62 Querying 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 81 This would result in the following output:: 82 83 Bar 51 84 }}} 52 53 This would result in the following output:54 55 {{{56 #!xml57 Bar58 }}}59 60 == Matching in Templates ==61 62 See MarkupTemplates#py:match63 85 64 86 ----