我想从文件“new.xml”中删除xml标签,并根据打印语句放置数据。
我尝试过:
from lxml import etree
tree = etree.parse("C:\\Users\\name\\Desktop\\new.xml")
root = tree.getroot()
for text in root.iter():
print text.text
XML 代码是:
<connection>
<rhel>
<runscript>y</runscript>
<username>useranme</username>
<password>passw</password>
<store>None</store>
<port>2</port>
<host>192.168.73.56</host>
<logdirectory>logs</logdirectory>
</rhel>
</connection>
我得到以下输出:
yes
username
passw
None
2
192.168.73.56
logs
但我想将其打印为:
is it a new connection: yes
username: username
password: passw
value: none
connections: 2
host: 192.168.73.56
log dir : logs