From the course: Learning Python

Unlock the full course today

Join today to access over 23,100 courses taught by industry experts.

Manipulating XML

Manipulating XML - Python Tutorial

From the course: Learning Python

Manipulating XML

- Sometimes when you're processing markup like XML or HTML, you don't want to build a parser that just runs through the document one line at a time. What you'll need to do is have the entire document in memory so you can manipulate it. In other words, you'll operate on the Documents Object Model or DOM. In this example, we'll see how to use the XML Mini DOM class that Python provides to load an XML file and then operate on the document while it's in memory. So let's open up the XML parsing start file. And the first thing I'm going to do is import the module that let's me operate on an XML DOM. So I'm going to import xml.dom.minidom, and the XML file I'm going to be parsing is this one right here. This is sample XML and if you open it up and look at it, you can see it's a pretty standard XML file. It's just got some basic information about a person in it. So here's my name, where I live, some skills that I have, again…

Contents