# # Example file for parsing and processing XML # (For Python 3.x, be sure to use the ExampleSnippets3.txt file) import xml.dom.minidom def main(): # use the parse() function to load and parse an XML file doc = xml.dom.minidom.parse("samplexml.xml"); # print out the document node and the name of the first child tag print doc.nodeName print doc.firstChild.tagName # get a list of XML tags from the document and print each one skills = doc.getElementsByTagName("skill") print "%d skills:" % skills.length for skill in skills: print skill.getAttribute("name") # create a new XML tag and add it into the document newSkill = doc.createElement("skill") newSkill.setAttribute("name", "jQuery") doc.firstChild.appendChild(newSkill) skills = doc.getElementsByTagName("skill") print "%d skills:" % skills.length for skill in skills: print skill.getAttribute("name") if __name__ == "__main__": main();
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question