[XML-SIG] Re: Encoding again

Fredrik Lundh fredrik at pythonware.com
Mon Apr 19 16:12:55 EDT 2004

Eustaquio Rangel de Oliveira Jr wrote:

> I'm running it on the console, not saving to a file.
> I'm using this:
> import libxml2
> import libxslt
> styledoc = libxml2.parseFile("impmod.xsl")
> style = libxslt.parseStylesheetDoc(styledoc)
> mods     = ("/home/taq/progs.xml","/home/taq/progs2.xml");
> for mod in mods:
> doc = libxml2.parseFile(mod)
> result = style.applyStylesheet(doc,None)
> print result.content
> style.freeStylesheet()
> doc.freeDoc()
> result.freeDoc()
> There on "print result.content" is where the weird chars are. I'd like
> to make it works first viewing on the console and so maybe saving it to
> a file.

the "content" attribute contains the content of an element, using the
default encoding.

digging a little more, it looks as if you can use the "serialize" method
to get the result you want:

    print result.serialize("iso-8859-1")

> That None value on applyStylesheet is kind of misterous to me. I'm a
> little confused by some questions as where I can get the API guide of
> all the functions I can use with libxml2/libslt with Python (dir works
> but it will be a cool thing find the APIs somewhere ehehe).

>>> help(libxml2)
>>> help(libxslt)

also see: http://www.xmlsoft.org/

> For example, didn't know about xmlSaveFileEnc and xmlSaveFileTo, where
> are they?

somewhere inside libxml2, I suppose. looking again, the functions seem to be
available as "SaveTo" and "SaveFileTo" and "SaveFileEnc" methods on the

hope this helps!


More information about the XML-SIG mailing list