Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将特定xml标记的值插入python元组 下面是xml文件:Results.xml 错误:_Python_Xml - Fatal编程技术网

将特定xml标记的值插入python元组 下面是xml文件:Results.xml 错误:

将特定xml标记的值插入python元组 下面是xml文件:Results.xml 错误:,python,xml,Python,Xml,请在这方面帮助我您遇到的问题是,在第一个标签中,您没有CMV_FREQ,因此当您尝试使用它时,它会失败: >>> for combin in root.findall('Combination'): ... for param in combin.getiterator('Parameter'): ... param.get('CMV_FREQ').text ... Traceback (most recent call last): File "&

请在这方面帮助我

您遇到的问题是,在第一个标签中,您没有CMV_FREQ,因此当您尝试使用它时,它会失败:

>>> for combin in root.findall('Combination'):
...    for param in  combin.getiterator('Parameter'):
...        param.get('CMV_FREQ').text
... 
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
AttributeError: 'NoneType' object has no attribute 'text'
另一个问题 peep=rr=[] 使peep==rr 因此,当您更改rr时,peep也将更新 如果您将代码保持原样,那么结果应该是

[((None, '1.0'), 'true'), ((None, '4.0'), 'false')] [((None, '1.0'), 'true'), ((None, '4.0'), 'false')]
而不是:

[((None, '1.0'), 'true')] [((None, '4.0'), 'false')]
peep = ((PEEP, 1.0), true)        # I want to check the tag before enter value and corresponding true will be insert into variable
rr   = ((CMV_FREQ, 4.0), false)
>>> for combin in root.findall('Combination'):
...    for param in  combin.getiterator('Parameter'):
...        param.get('CMV_FREQ').text
... 
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
AttributeError: 'NoneType' object has no attribute 'text'
  for combin in root.findall('Combination'):
    peep = []
    rr = []
    print 1
    for param in combin.getiterator('Parameter'):
      if param.find('PEEP') is not None: ##This will check if PEEP tag exists
         peep.append(((param.get('PEEP'), param.find('PEEP').text), param.find('Result').text))
      elif  param.find('CMV_FREQ') is not None:##This will check if CMV_FREQ tag exists
         rr.append(((param.get('CMV_FREQ'), param.find('CMV_FREQ').text), param.find('Result').text))
    print peep, rr
[((None, '1.0'), 'true'), ((None, '4.0'), 'false')] [((None, '1.0'), 'true'), ((None, '4.0'), 'false')]
[((None, '1.0'), 'true')] [((None, '4.0'), 'false')]