Error when parsing attributes with python minidom -


i have structure in xml file:

<questions>     <q question="where jim , mother going?" answer="the school"/>     <q question="what color ball?" answer="orange"/> 

i trying parse minidom in python

questionsblock = s.getelementsbytagname('questions')     questions = questionsblock[0].getelementsbytagname('q') counter = 1 q in questions:     question = q.attributes['question'].value     answer = q.attributes['answer'].value 

and getting error:

file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/xml/dom/minidom.py", line 524, in __getitem__ keyerror: 'answer' 

what missing here?

as far can tell code posted, there absolutely nothing wrong.

however, considering xml provided in extract, , not show </questions> closing tag, suspect there may q element somewhere missing answer attribute.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -