diff options
| author | scoder <none@none> | 2006-06-23 12:01:34 +0200 |
|---|---|---|
| committer | scoder <none@none> | 2006-06-23 12:01:34 +0200 |
| commit | cae536cc40680b6c4c0439983acd716384331f44 (patch) | |
| tree | 1481d84d14ea97633f8c83166c25b57872bf0532 /selftest.py | |
| parent | 649fd575505ec3f4672eeb9451a926a0e4836847 (diff) | |
| download | python-lxml-cae536cc40680b6c4c0439983acd716384331f44.tar.gz | |
[svn r1571] merge of iterparse branch: iterparse and iterwalk functions
--HG--
branch : trunk
Diffstat (limited to 'selftest.py')
| -rw-r--r-- | selftest.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/selftest.py b/selftest.py index ebbb8c26..1d5b1bb9 100644 --- a/selftest.py +++ b/selftest.py @@ -306,6 +306,73 @@ def parsefile(): ## </root> ## """ +def iterparse(): + """ + Test iterparse interface. + + >>> iterparse = ElementTree.iterparse + + >>> context = iterparse("samples/simple.xml") + >>> for action, elem in context: + ... print action, elem.tag + end element + end element + end empty-element + end root + >>> context.root.tag + 'root' + + >>> context = iterparse("samples/simple-ns.xml") + >>> for action, elem in context: + ... print action, elem.tag + end {namespace}element + end {namespace}element + end {namespace}empty-element + end {namespace}root + + >>> events = () + >>> context = iterparse("samples/simple.xml", events) + >>> for action, elem in context: + ... print action, elem.tag + + >>> events = () + >>> context = iterparse("samples/simple.xml", events=events) + >>> for action, elem in context: + ... print action, elem.tag + + >>> events = ("start", "end") + >>> context = iterparse("samples/simple.xml", events) + >>> for action, elem in context: + ... print action, elem.tag + start root + start element + end element + start element + end element + start empty-element + end empty-element + end root + + >>> events = ("start", "end", "start-ns", "end-ns") + >>> context = iterparse("samples/simple-ns.xml", events) + >>> for action, elem in context: + ... if action in ("start", "end"): + ... print action, elem.tag + ... else: + ... print action, elem + start-ns ('', 'namespace') + start {namespace}root + start {namespace}element + end {namespace}element + start {namespace}element + end {namespace}element + start {namespace}empty-element + end {namespace}empty-element + end {namespace}root + end-ns None + + """ + ## def fancyparsefile(): ## """ ## Test the "fancy" parser. |
