Reputation: 43
I have got an xml data as a output for my code. And Now I wanted to get an element value from the obtained xml data. I have used following commands
data1 = r1.read()
dom = xml.dom.minidom.parseString(data1)
conference=dom.getElementsByTagName('totalResults')
print conference.node value
But I was unable get the value.
My xml code will be
<first:totalresults>100</first:totalresults>
and so on
So now I want the value 100 to be printed So can any one help me in solving this. I have been trying for this since last night please any one kindly help me.
Upvotes: 0
Views: 103
Reputation: 1538
I'd recommend you'd use etree
for an easier XML parsing :
from lxml import etree
myFile = open("file.xml", 'r')
tree = etree.parse(myFile)
data = tree.xpath('//ns:totalresults', namespaces={'ns': 'http://api.com'})
print data
Upvotes: 1