xml parsing

Alexandre Fayolle alf at leo.logilab.fr
Fri Apr 27 03:17:07 EDT 2001


On Thu, 26 Apr 2001 22:37:41 +0000, iddwb <iddwb at imap1.asu.edu> wrote:
>
>I'm looking at building a simple managemen system which passes data with
>xml.  Since I'm currently going through hell trying to understand smgllib,
>I'm not looking forward to this in python -- but --
>
>anyone have any examples of python code parsing xml?


If you use the DOM implementation that comes in the PyXML package 
(by the xml-sig), it can be as simple as:

from xml.dom.ext.reader import Sax2
document = Sax2.FromXml('<doc>here's a document</doc>')

And then you can access the various parts of the document using the DOM 
interfaces.

print document.documentElement.firstChild

Python 2.0 also offers SAX implementation. I can provide an example for this 
too if you want, but it really depends on the kind of XML processing you want 
to do, so maybe if you provided a more specific example, we could help better. 


Alexandre Fayolle
-- 
http://www.logilab.com 
Narval is the first software agent available as free software (GPL).
LOGILAB, Paris (France).



More information about the Python-list mailing list