我需要根據用戶輸入使用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