pugixml.pugi.StringWriter

class pugixml.pugi.StringWriter

Bases: XMLWriter

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/>'

Methods

__init__(self)

Initialize StringWriter.

__len__(self)

Return the contents size in bytes.

getvalue(self[, encoding, errors])

Return a string containing the entire contents of the buffer.

Member Documentation

__init__(self: pugixml.pugi.StringWriter) None

Initialize StringWriter.

__len__(self: pugixml.pugi.StringWriter) int

Return the contents size in bytes.

Returns:

The contents size in bytes.

getvalue(self: pugixml.pugi.StringWriter, encoding: str = 'utf-8', errors: str = 'strict') str

Return a string containing the entire contents of the buffer.

Parameters:
  • encoding – The codec registered for encoding to decode the buffer.

  • errors – The desired error handling scheme. See codecs.decode() for details.

Returns:

A string containing the entire contents of the buffer.