When parsing an XML file using Minido, the result is an error memoryerror because the file is too large. After the query is learned because minidom in the parsing is to put all the files in memory, very memory-intensive, so consider a different way to process the XML file.
ElementTreeCompared to minidom consumes less memory, the following is
ElementTreeSome simple usages of the XML source file are part of the content:#导入ElementTreeFrom Xml.etree import ElementTree#读入并解析XML文件, the tree structure is read inDoc = et.parse (XML file address)#.getroot () Get the root node of the XML fileroot = Self.doc.getroot ()#.findall () finds all child nodes under the root nodeHttpsample_nodes = Root.findall (' httpsample ') #httpSample为子节点的tag
For I in Httpsample_nodes:
Print ("The result of printing I is:", i)
#.attrib all property results for the node are present in the dictionary structure
Print ("The result of printing I.attrib is:", I.attrib)
#.attrib["RC"] get the attribute value of the node "RC"
Print (' Print i.attrib[' RC "] results are: ', i.attrib[" RC "])
# . GetChildren () Gets all the child nodes of the node,. GetChildren () [0] Gets the first child node of a child node
I.getchildren () [0]
#.text getting the contents of a node
Print ("The result of printing the text of I is:", I.text)
Print ("I first child node content is:", I.getchildren () [0].text)
The specific print results are as follows:
ElementTree parsing XML (minidom parsing XML large file, Memoryerror)