pugixml.pugi.XMLText

class pugixml.pugi.XMLText

Bases: pybind11_object

A helper for working with text inside PCDATA nodes.

Examples

>>> from pugixml import pugi
>>> doc = pugi.XMLDocument()
>>> doc.load_string('<node/>')
>>> node = doc.child('node')
>>> a = node.append_child('a').append_child(pugi.NODE_CDATA)
>>> a.text().set('foo')
>>> b = node.append_child(pugi.NODE_PCDATA)
>>> b.text().set('bar')
>>> c = node.append_child(pugi.NODE_ELEMENT)
>>> c.set_name('c')
>>> c.text().set('baz')
>>> node.print(pugi.PrintWriter(), indent=' ')
<node>
 <a><![CDATA[foo]]></a>bar<c>baz</c>
</node>

Methods

__bool__(self)

Determine if this object is not empty.

__init__(self)

Initialize XMLText as an empty text.

as_bool(self[, default])

Return the contents as a boolean.

as_double(self[, default])

Return the contents as a number [DBL_MIN, DBL_MAX].

as_float(self[, default])

Return the contents as a number [FLT_MIN, FLT_MAX].

as_int(self[, default])

Return the contents as a number [INT_MIN, INT_MAX].

as_llong(self[, default])

Return the contents as a number [LLONG_MIN, LLONG_MAX].

as_string(self[, default])

Return the contents.

as_uint(self[, default])

Return the contents as a number [0, UINT_MAX].

as_ullong(self[, default])

Return the contents as a number [0, ULLONG_MAX].

data(self)

Return the data node (NODE_PCDATA or NODE_CDATA) for this object.

empty(self)

Determine if this object is empty.

get(self)

Return the contents.

set(*args, **kwargs)

Overloaded function.

Member Documentation

__bool__(self: pugixml.pugi.XMLText) bool

Determine if this object is not empty.

Returns:

True if the object is not empty, False otherwise.

__init__(self: pugixml.pugi.XMLText) None

Initialize XMLText as an empty text.

as_bool(self: pugixml.pugi.XMLText, default: bool = False) bool

Return the contents as a boolean.

Parameters:

default – The default value.

Returns:

The contents as a boolean (returns True if first character is in ‘1tTyY’ set), or the default value if the conversion fails or the object is empty.

as_double(self: pugixml.pugi.XMLText, default: SupportsFloat | SupportsIndex = 0) float

Return the contents as a number [DBL_MIN, DBL_MAX].

Parameters:

default – The default value.

Returns:

The contents as a number, or the default value if the conversion fails or the object is empty.

as_float(self: pugixml.pugi.XMLText, default: SupportsFloat | SupportsIndex = 0) float

Return the contents as a number [FLT_MIN, FLT_MAX].

Parameters:

default – The default value.

Returns:

The contents as a number, or the default value if the conversion fails or the object is empty.

as_int(self: pugixml.pugi.XMLText, default: SupportsInt | SupportsIndex = 0) int

Return the contents as a number [INT_MIN, INT_MAX].

Parameters:

default – The default value.

Returns:

The contents as a number, or the default value if the conversion fails or the object is empty.

as_llong(self: pugixml.pugi.XMLText, default: SupportsInt | SupportsIndex = 0) int

Return the contents as a number [LLONG_MIN, LLONG_MAX].

Parameters:

default – The default value.

Returns:

The contents as a number, or the default value if the conversion fails or the object is empty.

as_string(self: pugixml.pugi.XMLText, default: str = '') str

Return the contents.

Parameters:

default – The default value.

Returns:

The contents, or the default value if the object is empty.

as_uint(self: pugixml.pugi.XMLText, default: SupportsInt | SupportsIndex = 0) int

Return the contents as a number [0, UINT_MAX].

Parameters:

default – The default value.

Returns:

The contents as a number, or the default value if the conversion fails or the object is empty.

as_ullong(self: pugixml.pugi.XMLText, default: SupportsInt | SupportsIndex = 0) int

Return the contents as a number [0, ULLONG_MAX].

Parameters:

default – The default value.

Returns:

The contents as a number, or the default value if the conversion fails or the object is empty.

data(self: pugixml.pugi.XMLText) pugixml.pugi.XMLNode

Return the data node (NODE_PCDATA or NODE_CDATA) for this object.

Returns:

The data node for this object.

empty(self: pugixml.pugi.XMLText) bool

Determine if this object is empty.

Returns:

True if the object is empty, False otherwise.

get(self: pugixml.pugi.XMLText) str

Return the contents.

Returns:

The contents, or an empty string if the object is empty.

See also

as_string()

set(*args, **kwargs)

Overloaded function.

  1. set(self: pugixml.pugi.XMLText, value: str) -> bool

    Set the contents.

  2. set(self: pugixml.pugi.XMLText, value: str, size: typing.SupportsInt | typing.SupportsIndex) -> bool

    Set the contents with the specified length.

  3. set(self: pugixml.pugi.XMLText, value: bool) -> bool

    Set the contents as a boolean (true or false).

  4. set(self: pugixml.pugi.XMLText, value: float) -> bool

    Set the contents as a number [DBL_MIN, DBL_MAX].

  5. set(self: pugixml.pugi.XMLText, value: typing.SupportsFloat | typing.SupportsIndex, precision: typing.SupportsInt | typing.SupportsIndex) -> bool

    Set the contents as a number with the specified precision [DBL_MIN, DBL_MAX].

  6. set(self: pugixml.pugi.XMLText, value: typing.SupportsInt | typing.SupportsIndex) -> bool

    Set the contents as a number [LLONG_MIN, LLONG_MAX].

  7. set(self: pugixml.pugi.XMLText, value: typing.SupportsInt | typing.SupportsIndex) -> bool

    Set the contents as a number [0, ULLONG_MAX].

Parameters:
  • value – The contents to set.

  • size – The length of the contents as a string.

  • precision – The precision of the contents as a floating point number.

Returns:

False if the object is empty or there is not enough memory.