XML parsing per record

Willem Ligtenberg WLigtenberg at gmail.com
Fri Apr 22 14:02:16 EDT 2005


Since there are more than one database references possible per record you
should get per record a list of database names, database strings and
databases ids. (where the strings and the id's are really the same thing...)
So per record you check for both alternatives but since there could be
more than one, you do findall and get a (unsorted) list back. And now you
don't know which ID belonged to which database...
See my problem?

Cheers,

Willem

On Fri, 22 Apr 2005 19:38:03 +0200, Fredrik Lundh wrote:

> Willem Ligtenberg wrote:
> 
>> So I get a list database names and two! lists of ID's
>> And those two are in no way related. Is there an easy way to create a
>> dictionary like this DBname --> ID
> 
> why not just check for both alternatives?
> 
>     text = elem.findtext("Object-id_str")
>     if text is None:
>         text = elem.findtext("Object-id_id")
> 
> (or you can loop over the child elements and map elem.tag through a
> dictionary...)
> 
>> If not, I still might need to revert to SAX... :(
> 
> you still have to check for both alternatives...
> 
> (if you find a parsing problem that you cannot solve with a light-weight
> DOM, SAX won't help you...)
> 
> </F>




More information about the Python-list mailing list