I wrote a little utility called 'pyfo' for just this purpose. It works for generating any XML you like.
http://foss.cpcc.edu/pyfo/ this: ------------------------------- markup = ('div', [('h1', 'Example', {'class': 'heading'}), ('p', 'No one expects The Spanish Inquisition!')]) print pyfo(markup, pretty=True) ------------------------------- outputs: ------------------------------- <div> <h1 class="heading">Example</h1> <p>No one expects The Spanish Inquisition!</p> </div> ------------------------------- This has turned out to be extremely convenient for me. YMMV. Cheers, - Luke http://lukearno.com/ On 4/4/06, Ian Bicking <[EMAIL PROTECTED]> wrote: > Are there any opinions on the best HTML/XML generation libraries out there? > > For example, HTMLGen being the original (but too eclectic). Stan is > often also sited (http://divmod.org/projects/nevow#stan). I have an > extension of ElementTree along these lines in FormEncode > (http://svn.formencode.org/FormEncode/trunk/formencode/htmlgen.py). I > noticed http://markup.sourceforge.net/ today, which allows you to open a > tag and close it later, which can be nice. > > I'd like to put a Best Possible library in WebHelpers > (http://pylonshq.com/WebHelpers/), that's both simple and easy to work > with. I would be nice if the same API could be used to generate both > ElementTree nodes and strings; ElementTree itself can be a little picky, > so *only* using ElementTree as the internal/intermediate representation > (like formencode.htmlgen does) might be going too far. HTML/XHTML > validation might be interesting. Smart indentation would be nice, at > least optionally (i.e., indentation, but nothing that breaks the layout). > > While the library would ideally have some (optional) knowledge of HTML, > it would be out of scope to have it be a general page-builder (like > HTMLGen, and a bit like markup.sf.net). I'm more interested in just > using it to build fragments. > > Opinions? > > -- > Ian Bicking / [EMAIL PROTECTED] / http://blog.ianbicking.org > _______________________________________________ > Web-SIG mailing list > [email protected] > Web SIG: http://www.python.org/sigs/web-sig > Unsubscribe: > http://mail.python.org/mailman/options/web-sig/luke.arno%40gmail.com > _______________________________________________ Web-SIG mailing list [email protected] Web SIG: http://www.python.org/sigs/web-sig Unsubscribe: http://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com
