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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -