[Zope] python ques
AM
list_subscriber@neurobs.com
Tue, 20 Aug 2002 23:06:33 -0700
Hi all,
I realize the following is a python question but my post on
comp.lang.python has been languishing there for some time now without
any replies, so I just wanted to check if any of you knew a way out of
my problem...
I am trying to convert XML docs to HTML docs using an XSL file on the
fly. The function (external method ) that I have which does it is
the following:
## code begin
import libxml2
import libxslt
styledoc = libxml2.parseFile("page.xsl")
style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.parseFile("xml_file.xml")
result = style.applyStylesheet(doc, None)
#---
style.saveResultToFilename("-", result, 0)
#---
style.freeStylesheet()
doc.freeDoc()
result.freeDoc()
## code end
Now the only problem with this is that result which is an xmldoc
object can only save to a file, I looked at the source of
libxml.py:xmldoc. It can dump and save in a variety of ways but only
to a file or if the arg is "-", as above, to the standard output.
I wanted to save the contents of result to a string which I could then
send back as part of the RESPONSE object.
So I have two ques:
1. If possible, how do I save the contents directly to a string so as
to bypass the whole "print open(html_file).read()" thing??
OR
2. How do I trap the output being sent to stdout and capture it into a
string??
TIA
AM
--
==================================================================
Aseem Mohanty
Neurobehavioral Systems Inc, 828 San Pablo Ave, Albany, CA 94706
(R) 510 7696011 (M) 510 3014871 (O) 510 5279231
==================================================================
"I saw `cout' being shifted "Hello world" times to the left and
stopped right there!!" -- Steve Gonedes
==================================================================