【发布时间】:2017-09-21 05:37:10
【问题描述】:
我尝试使用不同的 python3 模块和来自互联网的不同文章来解析 XML,但没有成功。
我有这个 XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Header/>
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<cwmp:GetParameterValuesResponse>
<ParameterList SOAP-ENC:arrayType="cwmp:ParameterValueStruct[3]">
<ParameterValueStruct>
<Name>SOME_NAME_1_HERE</Name>
<Value>2</Value>
</ParameterValueStruct>
<ParameterValueStruct>
<Name>SOME_NAME_2_HERE</Name>
<Value>180</Value>
</ParameterValueStruct>
<ParameterValueStruct>
<Name>SOME_NAME_3_HERE</Name>
<Value>1800</Value>
</ParameterValueStruct>
</ParameterList>
</cwmp:GetParameterValuesResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我需要从 XML 标签中获取数据:名称和值 它应该是这样的:
SOME_NAME_1_HERE 2
SOME_NAME_2_HERE 180
SOME_NAME_3_HERE 1800
如何使用 Python3 获取这些值(最好使用 python 默认模块 - 而不是 bs4)?
谢谢
【问题讨论】:
标签: xml python-3.x xml-parsing