[Tutor] xml parsing

alan.gauld@bt.com alan.gauld@bt.com
Fri Nov 22 06:51:00 2002


Hi Ike,

> Thanks too all of you for steering me away from re.  I have 
> however managed to work out a nice solution to my problem on my own.  

This will work for the XML string you showed us as a sample, I'm not 
sure it will handle all XML tag types though.

For example attributed tags 

<xxx foo=yyy zzz=aaa>
   XXXXXX
</xxx>
and single tags 

</mmm ttt=bbbb>

(ie. where there is no separate matching </mmm> tag.)
It might work I just haven't tried it or looked closely enough 
to be sure.


> I would like to hear comments on any tricks that might make this more 
> efficent. (fortunately it is very short).

> item=item=XMLstring[XMLstring.find('>')+1:XMLstring.find('</'+
> key+'>')]

Is this a bug? or did you mean to have item=item=...

> This doesn't seem to be the fastest thing ever, but it does the job.  
> comments anyone?  could this possibly be 'useless python'? 

Definitely good for Useless I think.

Alan G.