I have an xml file:
<movie title="Enemy Behind">
<type>War, Thriller</type>
<type>WW2</type>
<format>DVD</format>
<year>2003</year>
<rating>PG</rating>
<stars>10</stars>
<description>Talk about a US-Japan war</description>
</movie>
And I am using the following code to Parse this XML in Python:
Print detail of each movie.
for movie in movies:
print ("*****Movie*****")
if movie.hasAttribute("title"):
print ("Title: %s" % movie.getAttribute("title"))
type = movie.getElementsByTagName('type')[0]
print ("Type: %s" % type.childNodes[0].data)
format = movie.getElementsByTagName('format')[0]
print ("Format: %s" % format.childNodes[0].data)
rating = movie.getElementsByTagName('rating')[0]
print ("Rating: %s" % rating.childNodes[0].data)
description = movie.getElementsByTagName('description')[0]
print ("Description: %s" % description.childNodes[0].data)
But using this code only one of the attribute gets printed i.e. "War, Thriller". The other attribute that says "WW2" doesn't get printed.
Should I use a for loop? I have tried that and I get an error "'Element' object is not iterable".