http://hg.4suite.org/amara/trunk/file/tip/demo/writing_xml.py
An excerpt:
from amara.writers.struct import *
w = structwriter().feed(
ROOT(
E(u'doc',
E(u'a', u'hello'),
E((u'b', None), u'this is unicode: \u221e'),
E(u'c', {u'parrot': u'dead', u'spam': u'eggs'}),
E(u'monty', E('spam', 'eggs')),
E(u'empty'),
E(u'func', lambda: u'this is a func'),
)
))
To generate:
<?xml version="1.0" encoding="UTF-8"?>
<doc><a>hello</a><b>this is unicode: ∞</b><c xmlns:parrot="dead"
xmlns:spam="eggs"/><monty><spam/></monty><empty/><func/></doc>
I've had such an idea for Amara for ages, but pyfo finally got me into
gear to implement it :) . Feedback on the API quite welcome, as well as
contributed test suites. Note, "raw" XML insertion APIs for the Amara
writers are planned, but not yet in place. Also, the indentation
support is pretty uneven at present.
Remember that you can try out Amara 2 without mucking with your Amara
1.x installation
using virtualenv.
http://pypi.python.org/pypi/virtualenv
I have a few notes here. See the "Test sandbox" heading:
http://wiki.xml3k.org/Amara2/Developer_notes
--
Uche Ogbuji http://uche.ogbuji.net
Founding Partner, Zepheira http://zepheira.com
Linked-in profile: http://www.linkedin.com/in/ucheogbuji
Articles: http://uche.ogbuji.net/tech/publications/
$ cat /tmp/sw.py; python /tmp/sw.py
from amara.writers.struct import *
w = structwriter().feed(
ROOT(
E(u'doc',
E(u'a', u'hello'),
E((u'b', None), u'this is unicode: \u221e'),
E(u'c', {u'parrot': u'dead', u'spam': u'eggs'}),
E(u'monty', E('spam', 'eggs')),
E(u'empty'),
E(u'func', lambda: u'this is a func'),
)
))
<?xml version="1.0" encoding="UTF-8"?>
<doc><a>hello</a><b>this is unicode: ∞</b><c xmlns:parrot="dead"
xmlns:spam="eggs"/><monty><spam>eggs</spam></monty><empty/><func>this is
a func</func></doc>