Package pyx12 :: Module xmlwriter :: Class XMLWriter
[hide private]

Class XMLWriter

source code

object --+
         |
        XMLWriter


Doctest:

    >>>from xmlwriter import XMLWriter
    >>>writer = XMLWriter()
    >>>writer.doctype(
    ... u"xsa", u"-//LM Garshol//DTD XML Software Autoupdate 1.0//EN//XML",
    ... u"http://www.garshol.priv.no/download/xsa/xsa.dtd")
    >>>#Notice: there is no error checking to ensure that the root element
    >>>#specified in the doctype matches the top-level element generated
    >>>writer.push(u"xsa")
    >>>#Another element with child elements
    >>>writer.push(u"vendor")
    >>>#Element with simple text (#PCDATA) content
    >>>writer.elem(u"name", u"Centigrade systems")
    >>>writer.elem(u"email", u"info@centigrade.bogus")
    >>>writer.elem(u"vendor", u"Centigrade systems")
    >>>#Close currently open element ("vendor)
    >>>writer.pop()
    >>>#Element with an attribute
    >>>writer.push(u"product", {u"id": u"100\u00B0"})
    >>>writer.elem(u"name", u"100\u00B0 Server")
    >>>writer.elem(u"version", u"1.0")
    >>>writer.elem(u"last-release", u"20030401")
    >>>#Empty element
    >>>writer.empty(u"changes")
    >>>writer.pop()
    >>>writer.pop()

startElement
endElement
emptyElement
text, data
endDocument
attribute
indentation
close
flush

Instance Methods [hide private]
 
__init__(self, out=sys.stdout, encoding='utf-8', indent=u' ')
out - a stream for the output encoding - an encoding used to wrap the output for unicode indent - white space used for indentation
source code
 
doctype(self, root, pubid, sysid)
Create a document type declaration (no internal subset)
source code
 
push(self, elem, attrs={})
Create an element which will have child elements
source code
 
elem(self, elem, content, attrs={})
Create an element with text content only
source code
 
empty(self, elem, attrs={})
Create an empty element
source code
 
pop(self)
Close an element started with the push() method
source code
 
__len__(self) source code
 
_indent(self) source code
 
_escape_cont(self, text) source code
 
_escape_attr(self, text) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, out=sys.stdout, encoding='utf-8', indent=u' ')
(Constructor)

source code 

out - a stream for the output encoding - an encoding used to wrap the output for unicode indent - white space used for indentation

Overrides: object.__init__