/ Published in: Python

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# Userful: http://blog.doughellmann.com/2010/03/pymotw-parsing-xml-documents-with.html from xml.etree import ElementTree foo = """<?xml version="1.0" encoding="utf-8"?> <ApiResponse Status="OK" xmlns="http://api.namecheap.com/xml.response"> <Errors /> <Warnings /> <RequestedCommand>namecheap.domains.check</RequestedCommand> <CommandResponse> <DomainCheckResult Domain="example.com" Available="false" /> </CommandResponse> <Server>P2136033</Server> <GMTTimeDifference>--7:00</GMTTimeDifference> <ExecutionTime>0.688</ExecutionTime> </ApiResponse>""" tree = ElementTree.fromstring(foo) print tree for node in tree.getiterator(): print node.tag, ": ", node.attrib print "\n--------------------\n" for node in tree.getiterator(): if "Available" in node.attrib.keys(): print node.attrib["Available"]
Comments
