XML parsing per record

Fredrik Lundh fredrik at pythonware.com
Fri Apr 22 16:51:39 EDT 2005


Willem Ligtenberg wrote:

> 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.

findall returns matching elements in document order.

> And now you don't know which ID belonged to which database...

why not?  by looking at each database separately, surely you must be
able to figure out if the subelement holds an ID or a string?  sure, if you
do document.findall(".//Object-id_id"), you'll get all IDs in document
order.  but if you do record.findall(".//Dbtag"), you get a list of all Dbtag
elements, and can then look inside them to see what they contain.

> See my problem?

I'm afraid not.  the document seems to have a clear structure; for some
reason, you don't seem to take that into account in your program.

</F>




More information about the Python-list mailing list