0
我一直停留在這個問題上幾天的現在時:問題解析XML文件
我有一個XML文件,它是與此類似(同項100S)
<?xml version='1.0' encoding='us-ascii'?>
<content>
<email a="1" b="0">[email protected]</email>
<email a="0" b="1">[email protected]</email>
</content>
我當前的代碼試圖通過這個XML文件解析:
from xml.dom import minidom
xmldoc = minidom.parse("data.xml")
content = xmldoc.getElementsByTagName("content")
address = xmldoc.getElementsByTagName("email")
for addresses in address:
Allow = True
Block = True
addressName = xmldoc.getElementsByTagName("email")
getB = addresses.attributes["b"]
b = getB.value
getA = addresses.attributes["a"]
a= getA.value
#setting allow and block list values
if (a == "1"):
Allow = True
print("This is allowed.")
elif (b == "1"):
Block = True
print("No, you cannot do that")
現在,我得到了以下的輸出:
<DOM Element: addr at 0x3102850>
This is allowed.
<DOM Element: addr at 0x3102850>
No, you cannot do that
我的預期/希望的結果是:
[email protected]
This is allowed.
[email protected]
No, you cannot do that
如果任何人都可以在正確的方向指向我,那將是美好的。我仍然在編程初學者,我有點停留在那一刻。我也對不起,如果格式不正確,這是我第一次發佈。
謝謝!