XML parsing per record

Fredrik Lundh fredrik at pythonware.com
Fri Apr 22 13:38:03 EDT 2005


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