[BangPypers] parsing xml
Anand Chitipothu
anandology at gmail.com
Thu Jul 28 12:03:13 CEST 2011
2011/7/28 Kenneth Gonsalves <lawgon at gmail.com>:
> hi,
>
> here is a simplified version of an xml file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <gpx >
> <metadata>
> <author>
> <name>CloudMade</name>
> <email id="support" domain="cloudmade.com" />
> <link href="http://maps.cloudmade.com"></link>
> </author>
> <copyright author="CloudMade">
> <license>http://cloudmade.com/faq#license</license>
> </copyright>
> <time>2011-07-28T07:04:01</time>
> </metadata>
> <extensions>
> <distance>1489</distance>
> <time>344</time>
> <start>Sägerstraße</start>
> <end>Im Gisinger Feld</end>
> </extensions>
> </gpx>
>
> I want to get the value of the distance element - 1489. What is the
> simplest way of doing this?
>>> from xml.dom import minidom
>>> dom = minidom.parseString(x)
>>> dom.getElementsByTagName("distance")[0].childNodes[0].nodeValue
u'1489'
Anand
More information about the BangPypers
mailing list