I\'m trying to get all the XML attributes for the tag Name.
Getting this error:
AttributeError: \'NoneType\' object has no attribute \'attr
BeautifulSoup is a HTML-parsing library, primarily. It can handle XML too, but all tags are lowercased as per the HTML specification. Quoting the BeautifulSoup documentation:
Because HTML tags and attributes are case-insensitive, all three HTML parsers convert tag and attribute names to lowercase. That is, the markup
is converted to. If you want to preserve mixed-case or uppercase tags and attributes, you’ll need to parse the document as XML.
There is a XML modus where tags are matches case-sensitively and are not lowercased, but this requires the lxml library to be installed. Because lxml is a C-extension library, this is not supported on the Google App Engine.
Use the ElementTree API instead:
import xml.etree.ElementTree as ET
root = ET.fromstring(xml)
div = root.find('.//Name')
for attr, val in div.items():
print "%s:%s" % (attr, val)