Errno 36: File name too long error parsing python XML
I have an XML file I am trying to parse and access one root of: DonorAdvisedFundInd
which I shouldn’t have a problem with but when I’m trying to parse the XML file I get an error message saying:
[Errno 36] File name too long:`
Here’s the code I’m currently using: I cut off most of it so it’s easier to see the problem. The error is occurring on the parse line.
import pandas as pd import xml.etree.ElementTree as et import requests xml_data = requests.get("https://s3.amazonaws.com/irs-form-990/201903199349320465_public.xml").content xtree = et.parse(xml_data)
Now the reason I’m so confused is if you open that link, the XML file really isn’t all that long. It should be able to be parsed. I’m using IBM Watson Studio’s online compiler if it makes any difference.
I’d appreciate any insight or feedback anyone can provide.
Try fromstring
:
import pandas as pd import xml.etree.ElementTree as et import requests xml_data = requests.get("https://s3.amazonaws.com/irs-form-990/201903199349320465_public.xml").content xtree = et.fromstring(xml_data)
Update (for finding the specific element):
for i in xtree.findall(".//"): if 'DonorAdvisedFundInd' in i.tag: print(i.tag, i.attrib, i.text)
Another way would have been using this xmltodict
lib like this:
result = xmltodict.parse(xml_data) result['Return']['ReturnData']['IRS990']['DonorAdvisedFundInd']