loxun

Large output in XML using unicode and namespaces
Download

loxun Ranking & Summary

Advertisement

  • Rating:
  • License:
  • LGPL v3
  • Price:
  • FREE
  • Publisher Name:
  • Thomas Aglassinger
  • Publisher web site:

loxun Tags


loxun Description

Large output in XML using unicode and namespaces loxun is a Python library that can be used to write large output in XML using Unicode and namespaces. Of course you can also use it for small XML output with plain 8 bit strings and no namespaces.Here is a very basic example. First you have create an output stream. In many cases this would be a file, but for the sake of simplicity we use a StringIO here: >>> from StringIO import StringIO >>> out = StringIO() >>> xml = XmlWriter(out)Now write the content: >>> xml.addNamespace("xhtml", "http://www.w3.org/1999/xhtml") >>> xml.startTag("xhtml:html") >>> xml.startTag("xhtml:body") >>> xml.text("Hello world!") >>> xml.tag("xhtml:img", {"src": "smile.png", "alt": ":-)"}) >>> xml.endTag() >>> xml.endTag() >>> xml.close()And the result is: >>> print out.getvalue().rstrip("\r\n") < ?xml version="1.0" encoding="utf-8"? > < xhtml:html xlmns:xhtml="http://www.w3.org/1999/xhtml" > < xhtml:body > Hello world! < xhtml:img alt=":-)" src="smile.png" / > < /xhtml:body > < /xhtml:html >


loxun Related Software