Working with XML Documents and Python (Page 1 of 4 )
XML can be used for describing data without needing a database. However, this leaves us with the problem of interpreting the data embedded within the XML. This is where Python comes to the rescue, as Peyton explains.
Introduction
XML, or eXtensible Markup Language, is a useful tool for describing all sorts of data. Take a look at this example:
<?xml version="1.0" encoding="UTF-8"?>
<devshed>
<categories>
<python>
<article>
<title>MySQL Connectivity With Python</title>
<author>Icarus</author>
</article>
<article>
<title>Python UnZipped</title>
<author>Mark Lee Smith</author>
</article>
</python>
<php>
<article>
<title>Writing Clean and Efficient PHP Code</title>
<author>David Fells</author>
</article>
<article>
<title>Using the PHP Crypt Function</title>
<author>Chris Root</author>
</article>
</php>
</categories>
</devshed>
We describe four articles in the DevShed backend. We start with a tag named devshed. Inside it, the tag categories contains two names, python and php. Inside each of these is an article tag, containing a title tag and an author tag. With this system, we are able to describe the data contained very easily and with no database. The data can be modified later with little effort and by someone with little experience.
However, we are faced with the problem of interpreting the data embedded within the XML. We need something to parse it with. Python includes a few tools that can aid us in parsing the data, and we'll take a look at them in this article, learning about them through example.
Next: Organizing a Book Collection >>
More Python Articles
More By Peyton McCullough