Here is my xml
<Departments orgID="1234 " name="This is Demo Name">
<Department>
.
.
</Department>
<Department>
.
.
</Department>
</Departments>
I want to get attribute of this xml using orgID.
Suppose orgID=1234 then output should be
This is Demo Name
What i have tried ,
import urllib2
import lxml.etree as ET
url="url goes here"
xmldata = urllib2.urlopen(url).read()
root = ET.fromstring(xmldata)
print root.xpath('//Departments/orgID[text()="1234"]/preceding-sibling::name/text()')[0]
But getting error ,
Traceback (most recent call last):
File "D:\JAVA\test-img\test\test.py", line 12, in <module>
print root.xpath('//Departments/orgID[text()="1234"]/preceding-sibling::name/text()')[0]
IndexError: list index out of range
Whats wrong i am doing here ?