python:使用没有类的xmlns解析xml文件

下面是 XML 文件:


<Schedule xmlns="http://xmlns.xyz.com/fal/downtimeschedule/V1.0">

 <Downtime end="20181020000" id="10001197610_20181027000_201810000" mode="cold" start="20181020000"/>

 <PODS>

  <POD DC="US - Washing" deferUpgrade="true" name="ABCD" patching="Production" EndTime="20181028040000">

   <CR id="12345"/>

   <CR id="12346"/>

   <CR id="123"/>

  </POD>

  <POD DC="US - Washing" deferUpgrade="true" name="ABCD-TEST" patching="Production" EndTime="20181028040000">

   <CR id="12345"/>

   <CR id="12346"/>

   <CR id="123"/>

  </POD>

 </PODS>

我想在带有列的 csv 文件中提供输出


1> POD(name)

2> POD(DC)

3> POD(deferUpgrade)

有人可以在这里帮忙。是否可以使用库 xml.etree.ElementTree,因为我在生产环境中有这个。


下面是代码。


#!/usr/bin/python

import os

import pandas as pd

import requests

import xml.etree.ElementTree as ET


tree = ET.parse('schedule.xml')


root = tree.getroot()


print root

print root.findall('PODS')

for pods in root.iter('Schedule'):

 for pod in pods.iter('POD'):

    print pod.get('name')

输出:


<Element '{http://xmlns.oracle.com/falcm/flo/downtimeschedule/V1.0}Schedule' at 0x2ae6ed0>

[]


杨__羊羊
浏览 189回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python