Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
afnan47
GitHub Repository: afnan47/sem7
Path: blob/main/IR/Assignment 5/five_Xml.py
418 views
1
import xml.dom.minidom
2
3
def main():
4
# use the parse() function to load and parse an XML file
5
doc = xml.dom.minidom.parse("Myxml.xml");
6
7
# print out the document node and the name of the first child tag
8
print (doc.nodeName)
9
print (doc.firstChild.tagName)
10
# get a list of XML tags from the document and print each one
11
expertise = doc.getElementsByTagName("expertise")
12
print ("%d expertise:" % expertise.length)
13
for skill in expertise:
14
print (skill.getAttribute("name"))
15
16
# Write a new XML tag and add it into the document
17
newexpertise = doc.createElement("expertise")
18
newexpertise.setAttribute("name", "BigData")
19
doc.firstChild.appendChild(newexpertise)
20
print (" ")
21
22
expertise = doc.getElementsByTagName("expertise")
23
print ("%d expertise:" % expertise.length)
24
for skill in expertise:
25
print (skill.getAttribute("name"))
26
27
if __name__ == "__main__":
28
main();
29