xmltodict

OrderedDict: Unable Return the item of d with key key. Raises a KeyError

蹲街弑〆低调 提交于 2019-12-13 03:43:34
问题 Accessing xmltodict converted values. I have an xml that looks like this <PQ N="E90" RT="TG"> <CASES ASOF_DATE="8/11/2017" CREATE_DATE="8/13/2017" RECORDS="1130" > <CASE> <ID>E90</ID> I am trying to access the CASE dictionary. If I remove the second XML line and try returning d[PQ]['CASE'], I get the desire result Here is the code for that: def convert(xml_file, xml_attribs=True): with open(xml_file, "rb") as f: d = xmltodict.parse(f, xml_attribs=xml_attribs) return (d['FUND']) This is how

xmltodict after parse only 1 root key and all other data in 2nd key

不想你离开。 提交于 2019-12-07 12:55:29
Am I doing something wrong with importing with xmltodict. When I am importing the data I am receiving only 2 items the first the root level object and the 2nd the rest of the values. In [58]: with open('20160305RAND0_edit.xml') as f: ....: my = xmltodict.parse(f.read()) ....: for k in my.items(): ....: print(k[0]) meeting When I ask for the second key I receive the rest of the values. In [61]: with open('20160319RHIL0_edit.xml') as f: ....: my = xmltodict.parse(f.read()) ....: for k in my.items(): ....: print(k[1]) This is the file I am using. <meeting id="42736" barriertrial="0" venue=