ElementTree findall()永远找不到第一个孩子

时间:2018-12-13 11:30:58

标签: python xml-parsing elementtree

我在使用元素树进行XML解析时遇到问题,我想解析该文件:

if(count($profiles) > 0){
            return redirect()->action('NameController@name');
        }else{
            return view('user');
        }

这是我的代码:

<?xml version="1.0" encoding="UTF-8"?>
<Metrics xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://standards.iso.org/iso-iec/19086/-2/ed-1/en">
    <Metric description="CloudServiceAvailability" source="example" id="M_AVL_002" scale="RATIO">
        <Parameter id="P_001" parameterStatement="2.592 x10^6" unit="second"
            note="Parameter represents a 30 day billing cycle in seconds"/>
        <Expression id = "E_001" expressionStatement=" 100 x (P_001- M_TQD_001)/P_001" expressionLanguage="ISO80000" unit="percentage"/>
        <UnderlyingMetricRef refid="M_TQD_001"/>
    </Metric>
    <Metric description="TotalQualifiedDowntime" source="example" id="M_TQD_001" scale="RATIO" >
        <Expression id="E_001" expressionStatement="&#x3A3;(M_QDT_001)" expressionLanguage="ISO80000" unit="second"/>
        <UnderlyingMetricRef refid="M_QDT_001"/>
    </Metric>
</Metrics>

问题是我的程序永远不会进入循环。我已经阅读了所有相关主题并尝试过:

for metric in root.findall('Metric'):
    print("COUCOU1")
    paramsTable=[]
    rulesTable=[]
    expressionsTable=[]
    metricTable={}
    metricTable['id']=metric.get('id')
    metricTable['desc']=metric.get('description')

但没有任何效果,我不知道出了什么问题!

编辑:由于XML文件的结构,该问题与其他问题不同

0 个答案:

没有答案