【问题标题】:Parse through XML with Namespace(gml)使用命名空间 (gml) 解析 XML
【发布时间】:2017-10-09 11:24:12
【问题描述】:

我正在尝试解析我的 xml 文件,我认为它可以工作,但是当我打印坐标时,我只能在控制台上得到这个:“[ ]”。

我的代码如下所示:

tree = ET.parse(url)
root = tree.getroot()
namespaces = {'gml': 'http://www.opengis.net/gml#'}
print(root.findall('gml:coordinates', namespaces))

【问题讨论】:

    标签: python python-3.x xml-parsing


    【解决方案1】:
    tree = ET.parse(url)
    root = tree.getroot()
    for a in root.findall('.//{http://www.opengis.net/gml}coordinates'):
        print(a.text)
    

    这不是完全相同的代码,但它可以满足我的要求,所以这是我问题的答案。

    【讨论】:

      猜你喜欢
      • 2021-05-03
      • 2014-01-10
      • 2010-11-08
      • 2018-07-15
      • 2012-06-11
      • 2015-09-08
      • 2011-09-20
      相关资源
      最近更新 更多