我需要根据用户输入使用python搜索XML表单中的值,但是它会给出空白值。我在下面解释我的代码。无法使用Python从XML文件中获取搜索值
import xml.etree.ElementTree as ET
tree = ET.parse('roomlist.xml')
root = tree.getroot()
print(root.findall(".//*[@roomname=\"cottage\"]"))
我的XML文件如下。
<?xml version="1.0" ?><roomlist>
<location name="Bangalore">
<room id="1uy92j908u092">
<roomname> Aquarius </roomname>
<noseats> 10 </noseats>
<projectorscreen>yes</projectorscreen>
<videoconf>yes</videoconf>
</room>
</location>
<location name="Bhubaneswar"><room id="131198912460"><roomname>cottage</roomname><noseats>5</noseats><projectorscreen>Yes</projectorscreen><videoconf>Yes</videoconf></room></location><location name="puri"><room id="509955554930"><roomname>room1</roomname><noseats>10</noseats><projectorscreen>No</projectorscreen><videoconf>Yes</videoconf></room></location></roomlist>
这里没有数据来。在这里,我需要搜索所有数据后应推入一个数组。
显示预期结果 – RomanPerekhrest
'$ result = [{'lname':'Bhubaneswar','rname':'cottage','noseats':5,'projectorscreen':是,'video':'yes'}]' – satya
@RomanPerekhrest:My预期产出应该高于预期。 – satya