#! /usr/bin/python
# -*- coding: utf-8 -*-
import xml.dom.minidom
# your xml string
xmlContent = "..."
# dom parser
dom = xml.dom.minidom.parseString(xmlContent)
# get element with tag "photo"
photoList = dom.getElementsByTagName("photo")
# get attribute id's value of each 'photo' element
for photo in photoList:
print photo.attributes['id'].value
# -*- coding: utf-8 -*-
import xml.dom.minidom
# your xml string
xmlContent = "..."
# dom parser
dom = xml.dom.minidom.parseString(xmlContent)
# get element with tag "photo"
photoList = dom.getElementsByTagName("photo")
# get attribute id's value of each 'photo' element
for photo in photoList:
print photo.attributes['id'].value
Comments