DocumentFragment

DocumentFragment

Overview

DocumentFragment is a class in Aspose.Html FOSS for Python. Inherits from: Node.

A lightweight container for a sub-tree.

This class provides 28 methods for working with DocumentFragment objects in Python programs. Available methods include: __init__, add_event_listener, append, append_child, clone_node, compare_document_position, contains, dispatch_event, get_feature, get_root_node, get_user_data, has_child_nodes, and 16 additional methods. All public members are accessible to any Python application after installing the Aspose.Html FOSS for Python package. Properties: child_nodes, first_child, is_connected, last_child, next_sibling, node_name, and 7 more.

Properties

NameTypeAccessDescription
node_namestrRead'#document-fragment'
text_contentstr | NoneRead/WriteThe concatenation of all descendant Text node data (DFS order).
node_typeintReadInteger node type constant from NodeType.
node_valuestr | NoneRead/WriteCharacter data for CharacterData nodes; None otherwise.
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__(owner_document: Document | None)Calls init(owner_document) on this DocumentFragment instance.
prepend()Insert nodes before the first child of this fragment.
append()Append nodes as the last children of this fragment.
replace_children()Remove all children of this fragment, then append nodes.
query_selector(selector: str)"Element | None"Return the first element in this fragment matching selector.
query_selector_all(selector: str)"NodeList"Return a static NodeList of all elements in this fragment matching selector.
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