hanju
hanju

Reputation: 139

OSError: [Errno 22] Invalid argument Getting invalid argument while parsing xml in python

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>&lt;s&gt;&lt;u t="1" n="net://abc.com/" i="net.tcp://abc.com/" /&gt;&lt;u t="2"
" /&gt;&lt;/s&gt;</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

Answers (1)

Tatts123
Tatts123

Reputation: 97

ET.parse() is a function for reading xml from disk

try ET.fromstring(xml)

Upvotes: 7

Related Questions