Thanks all for your help.<br><br>I decided to go with iterparse but trying the simple example in the python interpreter led to an error (see below) and when I tried this with a much larger xml sample, it seemed to print the full elements, not the specific values of the element. For example, given what I entered in the python interpreter, the result would have been the full xml example, and not "Reminder" "Don't forget me this weekend". <br>
<br>Did I do something wrong in the sample below? Thanks again.<br><br>>>> from xml.etree.cElementTree import iterparse<br>>>> sample = '''\<br>... <note><br>... <to>Tove</to><br>
... <from>Jani</from><br>... <heading>Reminder</heading><br>... <body>Don't forget me this weekend!</body><br>... </note><br>... '''<br>>>> print sample<br>
<note><br> <to>Tove</to><br> <from>Jani</from><br> <heading>Reminder</heading><br> <body>Don't forget me this weekend!</body><br></note><br><br>>>> for event, elem in iterparse(sample):<br>
... if elem.tag == 'note':<br>... print elem.findtext('heading'), elem.findtext('body')<br>... elem.clear()<br>...<br>... <br>Traceback (most recent call last):<br> File "<stdin>", line 1, in <module><br>
File "<string>", line 52, in __init__<br>IOError: [Errno 2] No such file or directory: "<note>\n\t<to>Tove</to>\n\t<from>Jani</from>\n\t<heading>Reminder</heading>\n\t<body>Don't forget me this weekend!</body>\n</note>\n"<br>
>>> <br><br><br><div class="gmail_quote">On Sun, Jun 20, 2010 at 4:32 AM, Stefan Behnel <span dir="ltr"><<a href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
please don't top-post, it makes your replies hard to read in context.<br>
<br>
Karim, 20.06.2010 10:24:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">
On 06/20/2010 10:14 AM, Stefan Behnel wrote:<br>
</div><div class="im"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Use ElementTree's iterparse:<br>
<br>
from xml.etree.cElementTree import iterparse<br>
</blockquote></div></blockquote>
>> [...]<div class="im"><br>
><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I know you are promoting Etree and I am very interesting in it.<br>
Is there any chance to have it integrated in future standard Python<br>
version?<br>
</blockquote>
<br></div>
The import above comes directly from the standard library (Python 2.5 and later). You may be referring to lxml.etree, which will most likely never make it into the stdlib.<div><div></div><div class="h5"><br>
<br>
Stefan<br>
<br>
_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</div></div></blockquote></div><br>