开发者

Set auto-incrementing attribute in XML node

开发者 https://www.devze.com 2022-12-18 10:07 出处:网络
I\'m trying to set an attribute in one of the nodes for my XML as below: rank = 1 for p开发者_如何学Choto in s:

I'm trying to set an attribute in one of the nodes for my XML as below:

rank = 1
for p开发者_如何学Choto 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 however results in the error: 'int' object has no attribute 'replace' in reference to the line: image.setAttribute("rank", rank) What am I missing?


The .setAttribute method expects a string, so you will have to convert it:

image.setAttribute("rank", str(rank))
0

精彩评论

暂无评论...
验证码 换一张
取 消