For a user-friendly introduction please see: http://www.xml3k.org/Amara/Tutorial#Writing_XML_.28and_HTML.29_from_nodes
Writing
Describes the Amara2 writing features, along with any open issues.
Use the xml_write() method to re-serialize to XML to a stream (sys.stdout by default). Use the xml_encode() method to re-serialize to XML, returning string.
node.xml_write(amara.writer.html) #Write out an XML document as pretty-printed HTML
node.xml_encode() #Return an XML string
node.xml_encode(amara.writer.html) #Return an indented HTML string
There are special methods to look up a printer class from strings such as "xml" and "html"
from amara.writer import lookup
XML_W = lookup("xml")
HTML_W = lookup("html")
node.xml_write(XML_W) #Write out an XML document
node.xml_encode(HTML_W) #Return an HTML string
Detailed function signatures:
def xml_encode(node, writer=XML_W, encoding='UTF-8', **kwargs): ... def xml_write(node, writer=XML_W, stream=None, encoding='UTF-8', **kwargs): ...
The default printer is the XML printer (i.e. amara.writer.lookup("xml"))
There will be many different printer classes, with different names indicating different capabilities or properties of the resulting output. Users can add new ones by calling the register(printer_name, printer_class) method.
amara.writers also contains a bunch of *Writer classes that are primarily used by Amara's XSLT engine. Writers depend upon the lower-level printer classes. The different aims of the two classes are:
- Printer - low level deserialization to output stream
- Writer - high level logic at the markup structural level
