This article mainly introduces how to parse dom elements in xml using Python. it analyzes the elements in XML using Python for reference, for more information about how to parse dom elements in xml, see the example in this article. Share it with you for your reference. The specific implementation method is as follows:
The code is as follows:
From xml. dom import minidom
Try:
Xmlfile = open ("path. xml", "a + ")
# Xmldoc = minidom. parse (sys. argv [1])
Xmldoc = minidom. parse (xmlfile)
Except t:
# Updatelogger. error ("Can't parse Xml File .")
Sys. exit (0)
ClientOutputPath = xmldoc. getElementsByTagName ('D') [0]. attributes ['path']. value
OutputPath = xmldoc. getElementsByTagName ('h') [0]. attributes ['path']. value
BasePath = xmldoc. getElementsByTagName ('th') [0]. attributes ['path']. value
ToolPath = xmldoc. getElementsByTagName ('UB ') [0]. attributes ['path']. value
ToolPath_2 = xmldoc. getElementsByTagName ('UB ') [1]. attributes ['path']. value
ClientOutputPath. replace ("\\","\\\\")
OutputPath. replace ("\\","\\\\")
BasePath. replace ("\\","\\\\")
ToolPath. replace ("\\","\\\\")
Print ClientOutputPath
Print OutputPath
Print BasePath
Print ToolPath
Print ToolPath_2
I hope this article will help you with Python programming.