Python XML processing (newbie question)

Jay jranchordas at
Mon Feb 10 17:57:18 CET 2003

Hello there, 

need help to extract certain pieces of info from an XML file:

<?xml version="1.0"?>





			<Description>One of the world's most popular

			<Name>Burger King</Name>

			<Description>One of the world's most popular





			<Name>Wheelwright's Arms</Name>

			<Description>A quiet pub located at the heart of the town near the
				     market place</Description>




			<Description>Woolworths - well worth it! Shop for CDs, DVDs, Games,






			<Description>Catalogue Shopping with a wide range of






			<Description>Barclays Bank</Description>




			<Description>For all your electronic accessories, camcorders,
			computing, gaming, Hi-Fi, mobile, peripherals, photograph, TV,
video 				and DVD needs in one place</Description>



			<Name>Hog's Head</Name>

			<Description>A friendly pub with a wide range of drinks perfectly
			suited for any taste</Description>






			<Description>HSBC - The World's Local Bank</Description>




			<Description>For all your toiletry needs</Description>

			<Name>Marks and Spencer</Name>

			<Description>For all your men, women or kids cloths, gifts, food,
			furniture needs</Description>





			<Name>Little Italy</Name>

			<Description>Italian specialty - Pizzas, pastas</Description>

			<Name>Pizza Hut</Name>

			<Description>Innovative Pizzas for any taste</Description>




			<Description>An all in one entertainment center with cinemas,
			restaurants, cafes, leisure clubs and a bowling


			<Description>If you enjoy playing Bingo, then this is the place for




I am using DOM and the code below simply displays the above XML onto
the screen (without tags).  What I want to do is search through the
tags (using getElementsByTagName or something similar) to extract
information such as bank tags only or shopping tags...(you get the
idea).  I was just getting the hang of Python and I have to go and do
something so complex.  Thanks in advance

from xml.dom import minidom

# this opens up the xml file to find the nearest user specified
xmldoc = minidom.parse('database.xml')
print "<p>"
# display entire XML document on screen
print xmldoc.toxml()
# this is where the parsing begins

More information about the Python-list mailing list