python-3.x - OSError: [Errno 22] Invalid argument 在 python 中解析 xml 时获取无效参数
问题描述
我在下面的 xml 中尝试提取所需的值
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>
'
我正在寻找的是从上面的 xml 中获取“活动”和“时间”的值
active=false
time=13:37:22
下面是代码
import xml.etree.ElementTree as ET
tree=ET.parse(xml)
print(tree)
但是解析没有按预期工作下面我收到以下错误
OSError:[Errno 22] 无效参数:
那么如何解决这个问题?
解决方案
ET.parse() 是一个从磁盘读取 xml 的函数
尝试 ET.fromstring(xml)
推荐阅读
- html - 使用 Ajax 单击按钮上的控制器无效方法。ASP.NET
- c - Clang 11 和 GCC 8 O2 破坏了内联装配
- mysql - 从未从前 5 名演员那里租过电影的客户列表(Sakila DB)
- django - 启动时出现 Django KeyError
- batch-file - 批处理脚本:将文件从父文件夹和子文件夹移动到新的子文件夹,重命名重复项
- javascript - 我如何只悬停一个特定元素而不是同时悬停两个
- flutter - 颤动中的单选按钮列表
- python - django 1.8版'ForeignKey'对象没有属性
- python - tensorlfow gradient.tape 可以与占位符一起使用吗?
- powershell - 从运行 Invoke-Command for Test-NetConnection 的脚本输入信息时,Export-csv 未在文件中写入内容