I was writing code to emit XHTML 1.1 using 4Suite and just to double-check the doc types I looked at the spec. I thought it might be useful to write up a small MarkupWriter example for emitting the example in the spec.
from Ft.Xml.MarkupWriter import MarkupWriter from xml.dom import XHTML_NAMESPACE, XML_NAMESPACE XHTML_NS = unicode(XHTML_NAMESPACE) XML_NS = unicode(XML_NAMESPACE) XHTML11_SYSID = u"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" XHTML11_PUBID = u"-//W3C//DTD XHTML 1.1//EN" writer = MarkupWriter(indent=u"yes", doctypeSystem=XHTML11_SYSID, doctypePublic=XHTML11_PUBID) writer.startDocument() writer.startElement(u'html', XHTML_NS, attributes={(u'xml:lang', XML_NS): u'en'}) writer.startElement(u'head', XHTML_NS) writer.simpleElement(u'title', XHTML_NS, content=u'Virtual Library') writer.endElement(u'head', XHTML_NS) writer.startElement(u'body', XHTML_NS) writer.startElement(u'p', XHTML_NS) writer.text(u'Moved to ') writer.simpleElement(u'a', XHTML_NS, attributes={u'href': u'http://vlib.org/'}, content=u'vlib.org') writer.text(u'.') writer.endElement(u'p', XHTML_NS) writer.endElement(u'body', XHTML_NS) writer.endElement(u'html', XHTML_NS) writer.endDocument()
It's worth mentioning that this example would be even simpler with template output facilities I've proposed for Amara.
via Copia