Re: [Tutor] Extracting xml text

2010-06-20 Thread Stefan Behnel
T.R. D., 20.06.2010 16:04: 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

Re: [Tutor] Extracting xml text

2010-06-20 Thread T.R. D.
Thanks all for your help. 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

Re: [Tutor] Extracting xml text

2010-06-20 Thread Stefan Behnel
Hi, please don't top-post, it makes your replies hard to read in context. Karim, 20.06.2010 10:24: On 06/20/2010 10:14 AM, Stefan Behnel wrote: Use ElementTree's iterparse: from xml.etree.cElementTree import iterparse >> [...] > I know you are promoting Etree and I am very interesting in it

Re: [Tutor] Extracting xml text

2010-06-20 Thread Karim
Hello Stefan, I know you are promoting Etree and I am very interesting in it. Is there any chance to have it integrated in future standard Python version? Regards Karim On 06/20/2010 10:14 AM, Stefan Behnel wrote: T.R. D., 20.06.2010 08:03: I'm trying to parse a list of xml strings and so fa

Re: [Tutor] Extracting xml text

2010-06-20 Thread Karim
In fact you must initialize the handler before parsing the xml doc and it should work. Regards Karim France On 06/20/2010 10:12 AM, Karim wrote: Hello, The following is an example which works for me to count opening tags in a xml doc, if it can help: # -*- coding: iso-8859-1 -*- import

Re: [Tutor] Extracting xml text

2010-06-20 Thread Stefan Behnel
T.R. D., 20.06.2010 08:03: I'm trying to parse a list of xml strings and so far it looks like the xml.parsers.expat is the way to go but I'm not quite sure how it works. I'm trying to parse something similar to the following. I'd like to collect all headings and bodies and associate them in a v

Re: [Tutor] Extracting xml text

2010-06-20 Thread Karim
Hello, The following is an example which works for me to count opening tags in a xml doc, if it can help: # -*- coding: iso-8859-1 -*- import sys from xml.parsers.expat import ParserCreate n = 0 def start_element(name, attrs): # callback declaration global n n += 1 parser =

[Tutor] Extracting xml text

2010-06-20 Thread T.R. D.
Hi, I'm trying to parse a list of xml strings and so far it looks like the xml.parsers.expat is the way to go but I'm not quite sure how it works. I'm trying to parse something similar to the following. I'd like to collect all headings and bodies and associate them in a variable (dictionary for