ANN: XMLBuilder 1.3
XMLBuilder is an easy way to generate XML. New in Version 1.3: * Support for non-ascii character. * You can specify the encoding when making the object. If not specified, it defaults to UTF-8. * Specify if you want the resulting XML to be pretty-printed out. Thanks to Luis Miguel Morillas for helping me with the encoding stuff, and the patches. The current version is always avaiable at: http://users.binary.net/thehaas/blogfiles//xmlbuilder.py It's easier to show you how XMLBuilder works than to tell you. Here is some samples:
b1.name={"person": {"attr": {"type":"friend"},"last":"flintstone", ... "first":"fred"}} print b1 <?xml version="1.0" encoding="utf-8"?> <name> <person type="friend"> <last> flintstone </last> <first> fred </first> </person> </name>
b2 = XMLBuilder() b2.person={"attr":{"type":"boss"}, "last":"Slate", "first":"Mr."} print b2 <?xml version="1.0" encoding="utf-8"?> <person type="boss"><last>Slate</last><first>Mr.</first></person>
print(b1+b2) <?xml version="1.0" encoding="utf-8"?> <name><person type="friend"><last>flintstone</last><first>fred</first> </person><person type="boss"><last>Slate</last><first>Mr.</first></person></name>
nonascii ={u"français" : u"Comment ça va? Trés bien?", ... u"deutsch" : u"viel Spaß"} ## encoding='local' means to use the local encoding, in my case ISO8859-1 iso = XMLBuilder(encoding="local", pretty=True) iso.lang = nonascii print iso <?xml version="1.0" encoding="ISO8859-1"?> <lang> <français> Comment ça va? Trés bien? </français> <deutsch> viel Spaß </deutsch> </lang>
A more concrete example is at: http://users.binary.net/thehaas/blogfiles/tablegen.py -- Mike Hostetler http://www.binary.net/thehaas
participants (1)
-
Mike Hostetler