我正在尝试email.xml
使用下面提供的 python 代码读取 xml 文件(下面的数据),我无法打印 xml 文件中存在的实际数据,但得到下面的输出。我哪里错了?
电流输出:
xmlfile
<open file 'email.xml', mode 'r' at 0x0226AF98>
[<DOM Element: to at 0x231d620>]
[<DOM Element: cc at 0x231d6c0>]
[<DOM Element: bcc at 0x231d760>]
蟒蛇代码:
import xml.dom.minidom as minidom
def getemaildata():
# Open the XML file
xmlfile = open('email.xml','r')
print "xmlfile"
print xmlfile
dom = minidom.parse(xmlfile)
email=dom.getElementsByTagName('email')
for node in email:
toemail=dom.getElementsByTagName('to')
print toemail
ccemail=dom.getElementsByTagName('cc')
print ccemail
bccemail=dom.getElementsByTagName('bcc')
print bccemail
return (toemail,ccemail,bccemail)
def main ():
(To,CC,BCC)=getemaildata()
if __name__ == '__main__':
main()
email.xml
文件:
<email>
<to>data@company.com;data.stability@company.com;
data.sns@company.com;data.pes@company.com;</to>
<cc> data.team </cc>
<bcc>data@company.com</bcc>
</email>