Найти - Пользователи
Полная версия: Получение значения из xml
Начало » Python для новичков » Получение значения из xml
1
XaidarM
Всем привет!
Подскажите пожалуйста, как вытащить значение “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>
<ns2aram>100</ns2aram>
</ns2:GetParam>
</return>
</ns3:GetParam>
</S:Body>
</S:Envelope>
py.user.next
  
>>> 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'
>>> 
XaidarM
Спасибо!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB