XML with Python - supposed to be simple? ;)

Gerhard Haering gerhard at bigfoot.de
Sun Jul 21 18:24:27 EDT 2002


* Vladimir Cherepanov [2002-07-22 01:17 +0400]:
> "Martin v. Loewis" <martin at v.loewis.de> wrote in message
> news:m3it38lsxm.fsf at mira.informatik.hu-berlin.de...
> > "Vladimir Cherepanov" <vovka_foreverREMOVE_THIS at hotmail.com> writes:
> >
> > > As a complete newbie to both XML and Python, I've been trying to
> > > create (any!) XML document using DOM API in PyXML package. Very
> > > simple task isn't it?
> > You'll then learn that you can create
> > Document instances by invoking createDocument on the
> > DOMImplementation. For minidom, you get the DOM implementation by
> > calling xml.dom.minidom.getDOMImplementation().
> 
> Thanks, I'll try this. Btw, I didn't find this method in DOMImplementation
> Interface - the only method I found was "hasFeature()".
> And what about serializing?

Here's a working example:

#!/usr/bin/env python
from xml.dom.minidom import getDOMImplementation

# requires PyXML:
from xml.dom.ext import PrettyPrint

impl = getDOMImplementation()
doc = impl.createDocument(None, "document", None)
root = doc.documentElement
foo = doc.createElement("foo")
root.appendChild(foo)

PrettyPrint(doc)

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))





More information about the Python-list mailing list