This web page and the other links above are tutorials on using the Perl Modules XML::DOM and XML::XPath to read and write XML documents.

The following is a link to the bottom of this page:
Obtaining the XML::DOM and XML::XPath modules.

This link shows how to use the XML::XPath module.
This link shows how to use the XML::DOM module


All the files used in these tutorials may be obtained from here which is a zip file. Unzip the file in a convenient directory where you plan on executing your Perl programs. Otherwise, there are links to each individual file as you go through the tutorials.

XML means "Extensible Markup Language". An XML document describes data in a manner that makes it easy to read.

Here is an example of a XML file (note that the programs and files may not be copied and pasted since they are image files. However, as we proceed through the tutorials, each program or file is explained and may be loaded individually.


<top> is the root element. <book>is a child of <top>. The book has a <book_title> element and has a number of <authors> where each author is described within <author> tags. In addition, we have a <description> of each copy of the book specified by its <condition> and its <price>. So the above XML document shows that our book is called "My first book" with the authors "Joe Stein" and "John Lacaree". One copy of the book is in "good" condition with a $100 price. There is another copy of the book with a "poor" condition with a price of $40, etc. <book> is a child of <top>. <book_title>, <authors> and <condition> are children of <book>. <author> is a child of <authors>. <price> and <condition> are all children of <descriptions>.

Notice that for each <tag> there is a corresponding </tag>

Load a similar file to the above called Book1.xml file by clicking here which shows an XML file with two books. This should automatically open in a browser window. Opening Book1.xml in a browser shows the structure. If a document is not a valid XML file, then the browser will complain and create an error message. Alternately, you can open an XML file using notepad++ which also shows the structure.

Here is another XML file which is similar to Book1.xml except as again, it lists only one book. A larger file with two books may be obtained by clicking here.


This contains the same information as the first XML document except that it is presented in a slightly different way. Instead of having a element <price>, there is an attribute of condition, namely "price".

Opening a XML document with notepad++ shows the structure also and allows you to modify files.

By clicking one of the two links at the top of this document, we show how to parse a XML document, how to modify a XML document, how to remove a child element and how to create a new XML document. In one case we use the Perl module XML::DOM and in the second case use XML::XPath.

Back to top.

Obtaining the XML::DOM and XML::XPath modules.

If you want to run Perl on a PC, then the most convenient way to find the XML::DOM and XML::XPath modules is to load Active Perl first. In a search engine, type "Active Perl" and you can then access the binaries for many machines which can be installed on our PC. You can then go to a command window and type "ppm" which stands for Perl Package Manager which brings you to a listing of installed and available Perl modules.

To load XML::DOM, you want to find XML-DOM (version 1.44) in the ppm window. To find the module XML::XPath, you want to look for XML-XPath (which is version 1.13) and install. The nice part of ppm is that it automatically loads all other modules required to run XML::DOM or XML::XPath.

One other option is to go to and find these modules and follow those directions to download them. If the modules have dependencies, then you need to download those modules also.

Back to top.