My question is I want to check a variable in a xml variable called xmlauthor and I want to check if there is just basically something written on it. How should I do it?
This is what I have written so far:
for num in ic :
xmlauthor = dom.getElementsByTagName("author")[0]
if not xmlauthor:
content += "***Changes by:" + xmlauthor + "*** \n \n"
else:
content += "***Changes are made Anonumously** \n \n"
And here is the error I am getting on my console
content += "***Changes by:" + xmlauthor + "*** \n\n"
TypeError: cannot concatenate 'str' and 'instance' objects
Assuming you’re using xml.dom: the
getElementsByTagNamedoesn’t return a list of strings, it returns a list of Element objects, so you can’t concatenatexmlauthorto a string in the lineYou could convert it to a string by changing it to: