【问题标题】:How can I open multiple XML documents stored in a single list?如何打开存储在单个列表中的多个 XML 文档?
【发布时间】:2014-10-14 14:45:36
【问题描述】:

这个 python 列表在一个 LIST 中包含多个 XML 文件。

list_xml = ['hello.xml,'hi.xml','08333.xml']

我想解析Hello.xml 并将数据存储到另一个列表中。完成后,我想阅读hi.xml

我该怎么做?

【问题讨论】:

  • 是什么阻止你这样做?
  • “解析 XML”是什么意思?是否要读取文件,然后将其存储为 Python 结构(字符串除外)?
  • 首先我必须访问第一个变量 'hello.xml .. 解析存储值并将其关闭到第二个变量,即“hi.xml”,然后解析存储值并关闭它..

标签: python xml-parsing


【解决方案1】:

请参阅以下代码的模式。这应该对您有所帮助。

另外,我建议您了解一些编程基础知识。

list_xml = ['a.xml', 'b.xml', ... ]
out = []
for xml in list_xml:
    # Parse XML here
    # more code
    out.append(parsed_data)
    return

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多