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
| Name | Type | Access | Description |
|---|---|---|---|
node_name | str | Read | '#document-fragment' |
text_content | str | None | Read/Write | The concatenation of all descendant Text node data (DFS order). |
node_type | int | Read | Integer node type constant from NodeType. |
node_value | str | None | Read/Write | Character data for CharacterData nodes; None otherwise. |
parent_node | Node | None | Read | The parent node, or None if this node has no parent. |
parent_element | Element | None | Read | The parent node if it is an Element; None otherwise. |
is_connected | bool | Read | Whether this node is part of a document’s node tree (WHATWG DOM §4.4). |
owner_document | Document | None | Read | The Document this node belongs to, or None for Document itself. |
child_nodes | NodeList | Read | A live NodeList of all child nodes. |
first_child | Node | None | Read | The first child node, or None. |
last_child | Node | None | Read | The last child node, or None. |
previous_sibling | Node | None | Read | The preceding sibling node, or None. |
next_sibling | Node | None | Read | The following sibling node, or None. |
Methods
| Signature | Description |
|---|---|
__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() → bool | Return whether this node has at least one direct child node. |
lookup_namespace_uri(prefix: str | None) → str | None | Return the effective namespace URI for prefix in this node context. |
lookup_prefix(namespace_uri: str | None) → str | None | Return the effective prefix for namespace_uri in this node context. |
is_default_namespace(namespace_uri: str | None) → bool | Return whether namespace_uri equals this node context default namespace. |
is_supported(feature: str, version: str | None) → bool | Return legacy feature-probe compatibility status. |
get_feature(feature: str, version: str | None) → object | None | Return the legacy feature object for a probe, or None. |
set_user_data(key: str, data: object | None, handler: object | None) → object | None | Store or clear node-local user data and return the previous value. |
get_user_data(key: str) → object | None | Return node-local user data for key or None when absent. |
append_child(node: Node) → Node | Append node as the last child of this node. |
insert_before(node: Node, reference: Node | None) → Node | Insert node before reference in the child list. |
remove_child(node: Node) → Node | Remove node from the child list and return it. |
replace_child(new_child: Node, old_child: Node) → Node | Replace old_child with new_child. |
clone_node(deep: bool) → Node | Return a copy of this node. |
normalize() | Put this node and its entire subtree into normalized form. |
contains(other: Node | None) → bool | Return True if other is an inclusive descendant of this node. |
compare_document_position(other: "Node") → int | Return a bitmask describing the position of other relative to this node. |
is_equal_node(other: Node | None) → bool | Return True if other has the same structure as this node. |
is_same_node(other_node: Node | None) → bool | Return 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") → bool | Dispatch event through the ancestor tree. |