下面是xml代码
<databases>
<source>
<host>prod</host>
<port>1522</port>
<user>P11</user>
<password>lXXXXX</password>
<tns>GP1</tns>
</source>
<target>
<host>bcp</host>
<port>1522</port>
<user>pg</user>
<password>yyyyy</password>
</target>
</databases>
现在要打印“user”和“tns”的值(如果“tns”存在),否则打印无效。已尝试使用Etree lxml,但没有得到预期的结果。 谢谢。你知道吗
确保您有python pip包
从控制台安装xmltodict python包(使用pip)
在python中
收到结果感谢您的及时回复
假设有多个
databases
标记嵌套在root
父节点中。将内容读入字符串(我使用的是多行Python字符串)然后,您可以通过以下操作获得所需的结果:
相关问题 更多 >
编程相关推荐