pugixml.pugi.StringWriterΒΆ

class pugixml.pugi.StringWriter

Bases: XMLWriter

(pugixml-python only) XMLWriter implementation for string.

See also

XMLNode.print()

Examples

>>> from pugixml import pugi
>>> doc = pugi.XMLDocument()
>>> doc.append_child('node')
>>> writer = pugi.StringWriter()
>>> doc.print(writer, flags=pugi.FORMAT_RAW)
>>> writer.getvalue()
'<node/>'
>>> writer = pugi.StringWriter()
>>> doc.print(writer, flags=pugi.FORMAT_RAW, encoding=pugi.ENCODING_UTF32_LE)
>>> writer.getvalue()
'<\x00\x00\x00n\x00\x00\x00o\x00\x00\x00d\x00\x00\x00e\x00\x00\x00/\x00\x00\x00>\x00\x00\x00'
>>> writer.getvalue('utf-32le')
'<node/>'

Members:

__init__(self)

Initialize StringWriter.

__len__(self)

Return the contents size in bytes.

getvalue(self[, encoding, errors])

Return a str containing the entire contents of the buffer.