Hello friends, I have a small problem with parsing XML documents...
My program works great, but if some element is not exist in the XML then I got an exception error, and now I want to ask "How to check if the element is in the XML" ?
Here is my code:
from xml.dom.minidom import parseString
...
doc = parseString( data )
items = doc.getElementsByTagName('item')
titles = []
links = []
for i in items:
titles.append( i.getElementsByTagName('title')[0].firstChild.data )
links.append( i.getElementsByTagName('link')[0].firstChild.data )
return dict( {'title' : titles, 'link' : links } )
XML code should be:
<item>
<title></title>
<link></link>
</item>
...and now, if title or link is not in the item, then I got the exception error (index out of range)...
So, "How to check if the element is in the XML" ?
Thanks