Reputation: 139
I have below xml where i am trying extract value which is required
xml = '<s:Envelope xmlns:s="schemas.xmlsoap.org/soap/envelope/"><s:Body><GetService xmlns="abc.com/Service">
<GetService xmlns:a="abc.com" xmlns:i="www.w3.org/2001/XMLSchema-instance">
<a:EnvironmentName>test</a:EnvironmentName><a:HasUpdates>true</a:HasNewUpdates><a:active>false</a:active><a:Time>13:37:22</a:Time><a:ServiceUrisString><s><u t="1" n="net://abc.com/" i="net.tcp://abc.com/" /><u t="2"
" /></s></a:ServiceUrisString></GetService></GetServiceRegistryResponse></s:Body></s:Envelope>
'
What iam looking for is to get the value for 'active' and 'time' from above xml
active=false
time=13:37:22
Below is the code
import xml.etree.ElementTree as ET
tree=ET.parse(xml)
print(tree)
But the parsing not working as expected Below I am getting following error
OSError: [Errno 22] Invalid argument:
SO how to resolve this issue?
Upvotes: 3
Views: 3041
Reputation: 97
ET.parse() is a function for reading xml from disk
try ET.fromstring(xml)
Upvotes: 7