In <[email protected]> Basant Dagar 
<[email protected]> writes:

> def lookup(d, keyval):
>     found = False
>     for child in d:
>         if found : return child.text
>         if child.tag == 'key' and child.text == keyval :
>             found = True
>     return None

> trackID = lookup(entry, 'Track ID')

> Below is the main part of input xml file data, it passes to lookup function:

> <key>Track ID</key><integer>369</integer>

> what I don't get is. How in the world it returns value 369 for the variable 
> 'trackID'??

It loops through the child items in entry, looking for one with a
'key' value of 'Track ID'.  If it finds one, it sets found=True and
loops one more time, returning the text of the *next* child element.

It depends on the 'key' element being directly followed by the 'integer'
element within entry.

-- 
John Gordon                   A is for Amy, who fell down the stairs
[email protected]              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to