XML help

Magnus Lie Hetland mlh at vier.idi.ntnu.no
Mon Mar 18 17:03:41 EST 2002


In article <AYpl8.16002$i66.686070 at wagner.videotron.net>, Vincent Foley wrote:
>Hi,
>
>  I have a XML document <http://freshmeat.net/projects-xml/vim/vim.xml>.
>I want to put the latest_version value in a variable.  How would I do
>that?

Well, to download it, you would probably simply use urllib (very easy
to use). To extract the value, you have many options. You don't really
have to use xml parsing for such a simple problem. E.g.:

from urllib import urlopen
url = 'http://freshmeat.net/projects-xml/vim/vim.xml'
for line in urlopen(url).readlines():
    start = line.find('<latest_version>')
    end   = line.find('</latest_version>')
    if -1 not in (start, end):
        print line[start+16:end]

On the other hand, using the xml libraries wouldn't be that hard
either.

>
>Thanks

--
Magnus Lie Hetland                                  The Anygui Project
http://hetland.org                                  http://anygui.org



More information about the Python-list mailing list