Форум сайта python.su
0
Всем привет!
Подскажите пожалуйста, как вытащить значение “Param” из xml следующей структуры:
<?xml version=“1.0” encoding=“UTF-8”?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/“>
<S:Body>
<ns3:GetParam xmlns:ns3=”http://devix.ru/integration/GetParam“ xmlns:ns2=”http://devix.ru/integration/GetParam">
<return>
<ns2:GetParam>
<ns2
aram>100</ns2
aram>
</ns2:GetParam>
</return>
</ns3:GetParam>
</S:Body>
</S:Envelope>
Офлайн
857
>>> import xml.etree.ElementTree as etree >>> >>> text = """\ ... <?xml version="1.0" encoding="UTF-8"?> ... <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> ... <S:Body> ... <ns3:GetParam xmlns:ns3="http://devix.ru/integration/GetParam" xmlns:ns2="http://devix.ru/integration/GetParam"> ... <return> ... <ns2:GetParam> ... <ns2:Param>100</ns2:Param> ... </ns2:GetParam> ... </return> ... </ns3:GetParam> ... </S:Body> ... </S:Envelope> ... """ >>> >>> doc = etree.fromstring(text) >>> >>> ns = {'ns2': "http://devix.ru/integration/GetParam"} >>> >>> node = doc.find('.//ns2:Param', namespaces=ns) >>> node.text '100' >>>
Отредактировано py.user.next (Сен. 27, 2017 08:45:24)
Офлайн
0
Спасибо!
Офлайн