python and parsing an xml file

Matt Funk mafunk at
Mon Feb 21 18:30:29 CET 2011

I was wondering if someone had some advice:
I want to create a set of xml input files to my code that look as follows:
<?xml version="1.0" encoding="UTF-8"?>

<!-- Settings for the algorithm to be performed                       

    <!-- The algorithm type.                                           
    <!-- The supported options are:                                    
    <!--     - Alg0                                                   
    <!--     - Alg1                                                   
    <!-- the location/path of the input file for this algorithm       

<!-- Relevant information during the processing will be written to a
logfile                                 -->
    <!-- the location/path of the logfile (i.e. where to put the
logfile)                                    -->
    <!-- verbosity level (i.e. how much to print)                       
    <!-- The supported options are:                                    
    <!--     - 0    (nothing printed)                                   
    <!--     - 1    (print on error)                                   


So there are comments, whitespace etc ... in it.
I would like to be able to put everything into some sort of structure
such that i can access it as:
structure['Algorithm']['Type'] == Alg1
I was wondering if there is something out there that does this.
I found and tried a few things:
It simply doesn't work. I get the following error:
raise exception
xml.sax._exceptions.SAXParseException: <unknown>:1:2: not well-formed
(invalid token)
But i removed everything from the file except: <?xml version="1.0"
and i still got the error.

Anyway, i looked at ElementTree, but that error out with:
xml.parsers.expat.ExpatError: junk after document element: line 19, column 0

Anyway, if anyone can give me advice of point me somewhere i'd greatly
appreciate it.


More information about the Python-list mailing list