Jul-05-2020, 12:49 AM
I am trying to read an XML file and access one specific attribute, in this case the
I also had another related question: currently I am doing this via an XML file stored on my computer, but how could I do this with an XML URL? like: https://s3.amazonaws.com/irs-form-990/20...public.xml
I appreciate any feedback and alternative suggestions anybody can provide. Thank you!
DisplayName
attribute, and use it to create a dataframe in Pandas. So far I've tried the following code:import xml.etree.ElementTree as et xtree = et.parse("XMLdata.xml") xroot = xtree.getroot() df_col = ["DAF"] df_rows = [] for node in xroot: is_DAF = node.find("DisplayName").text df_rows.append({"DAF":is_DAF}) out_df = pd.DataFrame(df_rows, columns = df_cols) out_dfbut I'm getting this error message:
AttributeError: 'NoneType' object has no attribute 'text'I've tried replacing
node.find("DisplayName").textwith
node.attrib.get("DisplayName)which doesn't return any errors but the dataframe contains "None" when the value should be "jalynne.k.archibald" as you can see from the sample XML file I attached below.
I also had another related question: currently I am doing this via an XML file stored on my computer, but how could I do this with an XML URL? like: https://s3.amazonaws.com/irs-form-990/20...public.xml
I appreciate any feedback and alternative suggestions anybody can provide. Thank you!