MCPcopy Create free account
hub / github.com/LinkedInLearning/learning-python-2896241 / main

Function main

Ch5 - Internet Data/xmlparsing_finished.py:9–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7import xml.dom.minidom
8
9def main():
10 # use the parse() function to load and parse an XML file
11 doc = xml.dom.minidom.parse("samplexml.xml")
12
13 # print out the document node and the name of the first child tag
14 print (doc.nodeName)
15 print (doc.firstChild.tagName)
16
17 # get a list of XML tags from the document and print each one
18 skills = doc.getElementsByTagName("skill")
19 print ("%d skills:" % skills.length)
20 for skill in skills:
21 print (skill.getAttribute("name"))
22
23 # create a new XML tag and add it into the document
24 newSkill = doc.createElement("skill")
25 newSkill.setAttribute("name", "jQuery")
26 doc.firstChild.appendChild(newSkill)
27
28 skills = doc.getElementsByTagName("skill")
29 print ("%d skills:" % skills.length)
30 for skill in skills:
31 print (skill.getAttribute("name"))
32
33if __name__ == "__main__":
34 main()

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected