捕捉信息xml.dom.minidom

2024-09-29 21:54:05 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的意见:
使用python 2.4

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

我只想用Lat注销这个。你知道吗

这是我使用的代码:

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

当我试着做以下事情的时候:

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

我用这个网站作为参考来做什么:

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

Tags: thedoctimetypestatusxmlthistemp
1条回答
网友
1楼 · 发布于 2024-09-29 21:54:05

对于您的示例,您可以使用下一个代码,在那里您将获得值Lat和Lon。你知道吗

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

相关问题 更多 >

    热门问题