2017-05-01 1 views
0

das ist mein Eingang:
mit Python 2,4Fangen Info mit xml.dom.minidom

<?xml version="1.0" encoding="UTF-8" ?> 
<Status> 
    <_IGPS> 
     <Lat>03°14'48"N</Lat> 
     <Lon>117°35'03"E</Lon> 
     <Type>3D</Type> 
     <Status>allowed</Status> 
     <Time>17/01/25,09:12:02</Time> 
    </_IGPS> 

und im Versuch, nur die Lat und Melden Sie sich von diesem zu nehmen.

dies ist der Code, den ich verwenden:

doc = minidom.parse("t.xml") 
temp = doc.getElementsByTagName("_IGPS") 
if i print this i get => "<xml.dom.minidom.Document instance at 0x02C01E68>" 
*** This is the part that i cant figure out to extract the actualy values *** 

auch bei somepoint, wenn ich versuche, Folgendes zu tun: als

print(temp.** at this point the interpeter does not know what is the type of temp** 

i verwendet diese Website als Referenz, was zu tun:

https://www.mkyong.com/python/python-read-xml-file-dom-example/ 

Antwort

0

für Ihr Beispiel könnten Sie nächsten Code verwenden, wo Sie die Werte Lat und Lon erhalten.

from xml.dom import minidom 

xml = minidom.parse('t.xml') 

lat = xml.getElementsByTagName('Lat')[0].firstChild.nodeValue 
lon = xml.getElementsByTagName('Lon')[0].firstChild.nodeValue 

print(lat) # 03°14'48"N 
print(lon) # 117°35'03"E 
+0

Vielen Dank. –

+0

Wenn die Antwort richtig ist, bitte als korrekt markieren, Danke. –