我用minidom解析一个很简单的xml不成功啊?
我用python2.6.4,写了这么一个python程序
from xml.dom import minidomtry: xmlfile = open("d:\\File1.xml", "a+") xmldoc = minidom.parse(xmlfile)except : sys.exit(0)Info = xmldoc.getElementsByTagName('Request_Info')[0]Attr = Info.attributes['Request_Type'];Type = Attr.value;print(Type)
<?xml version="1.0" encoding="utf-8" ?><TT_Msg> <Request_Info> <Request_Type>XML</Request_Type> <Result> <NewDataSet> <RecordsTable> <COMPONENT>MyComponent</COMPONENT> <DEVELOPER>MyName</DEVELOPER> <TITLE>When server starts, service crashes</TITLE> <ISSUEID>123456</ISSUEID> <ID>123456</ID> </RecordsTable> <MoreInfoTable> <MoreRecords>False</MoreRecords> <ID>456</ID> </MoreInfoTable> </NewDataSet> </Result> <Msg></Msg> </Request_Info></TT_Msg>