Set auto increment attribute in XML node

I am trying to set an attribute in one of the nodes for my XML, as shown below:

rank = 1
for photo in s:
  image = feed.createElement('Image')
  images.appendChild(image)
  image.setAttribute("rank", rank)
  p = feed.createTextNode(str(main_url+photo.display.url))
  image.appendChild(p)
  rank += 1

This leads to an error: 'int' object has no attribute 'replace'in relation to the line: image.setAttribute("rank", rank)What am I missing?

+3
source share
1 answer

.setAttributemethod expects a string, so you have to convert it:

image.setAttribute("rank", str(rank))
+1
source

Source: https://habr.com/ru/post/1729773/


All Articles