()
| 7 | import xml.dom.minidom |
| 8 | |
| 9 | def 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 | |
| 33 | if __name__ == "__main__": |
| 34 | main() |
no outgoing calls
no test coverage detected