Text

Overview

Text is a class in Aspose.Html FOSS for Python. Inherits from: CharacterData.

A text node.

This class provides 30 methods for working with Text objects in Python programs. Available methods include: __init__, add_event_listener, append_child, append_data, clone_node, compare_document_position, contains, delete_data, dispatch_event, get_feature, get_root_node, get_user_data, and 18 additional methods. All public members are accessible to any Python application after installing the Aspose.Html FOSS for Python package. Properties: child_nodes, data, first_child, is_connected, last_child, length, and 10 more.

Properties

NameTypeAccessDescription
node_namestrRead'#text'
whole_textstrReadConcatenated data of all contiguous Text nodes around this node.
node_valuestrRead/WriteThe character data content (same as data).
text_contentstr | NoneRead/WriteThe character data content (same as data).
datastrRead/WriteThe character data content.
lengthintReadThe number of code units in data.
node_typeintReadInteger node type constant from NodeType.
parent_nodeNode | NoneReadThe parent node, or None if this node has no parent.
parent_elementElement | NoneReadThe parent node if it is an Element; None otherwise.
is_connectedboolReadWhether this node is part of a document’s node tree (WHATWG DOM §4.4).
owner_documentDocument | NoneReadThe Document this node belongs to, or None for Document itself.
child_nodesNodeListReadA live NodeList of all child nodes.
first_childNode | NoneReadThe first child node, or None.
last_childNode | NoneReadThe last child node, or None.
previous_siblingNode | NoneReadThe preceding sibling node, or None.
next_siblingNode | NoneReadThe following sibling node, or None.

Methods

SignatureDescription
__init__(data: str, owner_document: Document | None)Calls init(data, owner_document) on this Text instance.
split_text(offset: int)"Text"Split this Text node at offset, returning the new trailing node.
substring_data(offset: int, count: int)strReturn a substring of data starting at offset for count chars.
append_data(data: str)Append data to the existing character data.
insert_data(offset: int, data: str)Insert data at offset.
delete_data(offset: int, count: int)Delete count characters starting at offset.
replace_data(offset: int, count: int, data: str)Replace count characters from offset with data.
remove()Remove this node from its parent node.
get_root_node(composed: bool)"Node"Return the root of the node’s tree.
has_child_nodes()boolReturn whether this node has at least one direct child node.
lookup_namespace_uri(prefix: str | None)str | NoneReturn the effective namespace URI for prefix in this node context.
lookup_prefix(namespace_uri: str | None)str | NoneReturn the effective prefix for namespace_uri in this node context.
is_default_namespace(namespace_uri: str | None)boolReturn whether namespace_uri equals this node context default namespace.
is_supported(feature: str, version: str | None)boolReturn legacy feature-probe compatibility status.
get_feature(feature: str, version: str | None)object | NoneReturn the legacy feature object for a probe, or None.
set_user_data(key: str, data: object | None, handler: object | None)object | NoneStore or clear node-local user data and return the previous value.
get_user_data(key: str)object | NoneReturn node-local user data for key or None when absent.
append_child(node: Node)NodeAppend node as the last child of this node.
insert_before(node: Node, reference: Node | None)NodeInsert node before reference in the child list.
remove_child(node: Node)NodeRemove node from the child list and return it.
replace_child(new_child: Node, old_child: Node)NodeReplace old_child with new_child.
clone_node(deep: bool)NodeReturn a copy of this node.
normalize()Put this node and its entire subtree into normalized form.
contains(other: Node | None)boolReturn True if other is an inclusive descendant of this node.
compare_document_position(other: "Node")intReturn a bitmask describing the position of other relative to this node.
is_equal_node(other: Node | None)boolReturn True if other has the same structure as this node.
is_same_node(other_node: Node | None)boolReturn True when other_node is this node instance.
add_event_listener(type: str, listener: Callable, capture: bool, once: bool)Register listener for events of type.
remove_event_listener(type: str, listener: Callable, capture: bool)Deregister a previously-registered listener.
dispatch_event(event: "Event")boolDispatch event through the ancestor tree.

See Also