probably a very simple question - but I'm a python/xml newbie and cant seem to find an answer that works for me.
I am trying to parse xml values and from an xml reponse as follows
#!/usr/bin/python3
from xml.etree import cElementTree as ET
xmlstr = """<?xml version="1.0" encoding="utf-8"?>
<biwsXML_response type="find">
<clientdata>
<message></message>
<query>jurnamn:Acme Ltd</query>
<wpquery></wpquery>
<wpfilter></wpfilter>
</clientdata>
<records total="1">
<record nr="1">
<nummer>9990874474</nummer>
<orgnr>9990874474</orgnr>
<jurnamn>Acme1 Ltd</jurnamn>
<ba_postort>Täby</ba_postort>
<abv_ugrupp></abv_ugrupp>
</record>
<record nr="2">
<nummer>9890874474</nummer>
<orgnr>9890874474</orgnr>
<jurnamn>Acme2 Ltd</jurnamn>
<ba_postort>Täby</ba_postort>
<abv_ugrupp></abv_ugrupp>
</record>
</records>
</biwsXML_response>
"""
biwsXML_response = ET.fromstring(xmlstr)
for records in list(biwsXML_response):
orgnr = records.find('orgnr').text
jurnamn = records.find('jurnamn').text
print('orgnr: %s; jurnamn: %s' % (orgnr, jurnamn))
When I test I get the following error.
Traceback (most recent call last):
File "read_xml_tst2.py", line 31, in <module>
orgnr = records.find('orgnr').text
AttributeError: 'NoneType' object has no attribute 'text'
I understand that I am not finding the value 'NoneType' but I don't understand were the error is. Thanks for any help.
clientdata. There is noorgnrelement (nor is there ajurnamn).