| 1 | = Using XPath in Markup = |
| 2 | |
| 3 | Markup provides basic [http://www.w3.org/TR/xpath XPath] support for matching and querying event streams. |
| 4 | |
| 5 | == Limitations == |
| 6 | |
| 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. |
| 8 | |
| 9 | In particular, only the following axes are supported: |
| 10 | * `attribute` |
| 11 | * `child` |
| 12 | * `descendant` |
| 13 | * `descendant-or-self` |
| 14 | * `namespace` (not completed yet) |
| 15 | * `self` |
| 16 | |
| 17 | In addition, Markup does not (yet) support numeric types in XPath: everything is treated as text or booleans. For that reason, [http://www.w3.org/TR/xpath#NT-RelationalExpr relational] or [http://www.w3.org/TR/xpath#NT-AdditiveExpr additive] operators such as `>`, `<`, or `<=`. |
| 18 | |
| 19 | == Querying Streams == |
| 20 | |
| 21 | {{{ |
| 22 | #!python |
| 23 | from markup.input import XML |
| 24 | |
| 25 | doc = XML('''<doc> |
| 26 | <items count="2"> |
| 27 | <item status="new"> |
| 28 | <summary>Foo</summary> |
| 29 | </item> |
| 30 | <item status="closed"> |
| 31 | <summary>Bar</summary> |
| 32 | </item> |
| 33 | </items> |
| 34 | </doc>''') |
| 35 | print doc.select('items/item[@status="closed"]/summary/text()') |
| 36 | }}} |
| 37 | |
| 38 | This would result in the following output: |
| 39 | |
| 40 | {{{ |
| 41 | #!xml |
| 42 | Bar |
| 43 | }}} |
| 44 | |
| 45 | == Matching in Templates == |
| 46 | |
| 47 | See MarkupTemplates#py:match |
| 48 | |
| 49 | ---- |
| 50 | See also: MarkupGuide, MarkupStream |