pyx12.xmlwriter

Classes

XMLWriter

Doctest:

Module Contents

class pyx12.xmlwriter.XMLWriter(out=sys.stdout, encoding='utf-8', indent=' ')[source]

Doctest:

>>>from xmlwriter import XMLWriter >>>writer = XMLWriter() >>>writer.doctype( … u”xsa”, u”-//LM Garshol//DTD XML Software Autoupdate 1.0//EN//XML”, … u”https://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”100u00B0”}) >>>writer.elem(u”name”, u”100u00B0 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

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

Parameters:
  • out (TextIO)

  • encoding (str)

  • indent (str)

encoding: str[source]
out: TextIO[source]
stack: list[str][source]
indent: str[source]
doctype(root, pubid, sysid)[source]

Create a document type declaration (no internal subset)

Parameters:
Return type:

None

push(elem, attrs=None)[source]

Create an element which will have child elements

Parameters:
Return type:

None

elem(elem, content, attrs=None)[source]

Create an element with text content only

Parameters:
Return type:

None

empty(elem, attrs=None)[source]

Create an empty element

Parameters:
Return type:

None

pop()[source]

Close an element started with the push() method

Return type:

None