You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Indirect accessor to set the 'owner_document' property."""
255
+
ifowner_documentisNone:
256
+
ifself.node_type!=NodeType.DOCUMENT_NODE:
257
+
raiseValueError('`Node` should have a `Document` object ',
258
+
'which associated with this node, ',
259
+
'Unless this node is a `Document`.')
267
260
self._owner_document=owner_document
268
261
262
+
definsert_before(self,
263
+
new_child: _AnyNode,
264
+
ref_child: Optional[_AnyNode] =None) ->_AnyNode:
265
+
"""Inserts the node `new_child` before the existing child node `ref_child`. If `ref_child` is `None`, insert `new_child` at the end of the list of children.
266
+
267
+
If `new_child` is a `DocumentFragment` object, all of its children are inserted, in the same order, before `ref_child`. If the `new_child` is already in the tree, it is first removed.
268
+
269
+
Args:
270
+
new_child: The node to insert.
271
+
ref_child: The reference node, i.e., the node before which the new node must be inserted.
272
+
273
+
Returns:
274
+
The node being inserted.
275
+
276
+
Raises:
277
+
DOMException:
278
+
- `HIERARCHY_REQUEST_ERR`: Raised if this node is of a type that does not allow children of the type of the `new_child` node, or if the node to insert is one of this node's ancestors.
279
+
- `WRONG_DOCUMENT_ERR`: Raised if `new_child` was created from a different document than the one that created this node.
280
+
- `NO_MODIFICATION_ALLOWED_ERR`: Raised if this node is readonly.
281
+
- `NOT_FOUND_ERR`: Raised if `ref_child` is not a child of this node.
282
+
"""
283
+
# `HIERARCHY_REQUEST_ERR` should be checked on subclasses by overriding.
# Otherwise, simply insert `new_child` using the methods of `NodeList(list)`.
315
+
ref_index=self.child_nodes.index(ref_child)
316
+
self.child_nodes.insert(ref_index, new_child)
317
+
new_child._set_parent_node(self)
318
+
returnnew_child
319
+
320
+
defreplace_child(self,
321
+
new_child: _AnyNode,
322
+
old_child: _AnyNode) ->_AnyNode:
323
+
"""Replaces the child node `old_child` with `new_child` in the list of children, and returns the `old_child` node.
324
+
325
+
If the `new_child` is already in the tree, it is first removed.
326
+
327
+
Args:
328
+
new_child: The new node to put in the child list.
329
+
old_child: The node being replaced in the list.
330
+
331
+
Returns:
332
+
The node replaced.
333
+
334
+
Raisees:
335
+
DOMException:
336
+
- `HIERARCHY_REQUEST_ERR`: Raised if this node is of a type that does not allow children of the type of the `new_child` node, or it the node to put in is one of this node's ancestors.
337
+
- `WRONG_DOCUMENT_ERR`: Raised if `new_child` was created from a different document than the one that created this node.
338
+
- `NO_MODIFICATION_ALLOWED_ERR`: Raised if this node is readonly.
339
+
- `NOT_FOUND_ERR`: Raised if `old_child` is not a child of this node.
340
+
"""
341
+
# `HIERARCHY_REQUEST_ERR` should be checked on subclasses by overriding.
"""Adds the node `new_child` to the end of the list of children of this node.
388
+
389
+
If the `new_child` is already in the tree, it is first removed.
390
+
391
+
Args:
392
+
new_child: The node to add. If it is a `DocumentFragment` object, the entire contents of the document fragment are moved into the child list of this node
393
+
394
+
Returns:
395
+
The node added.
396
+
397
+
Raises:
398
+
DOMException:
399
+
- `HIERARCHY_REQUEST_ERR`: Raised if this node is of a type that does not allow children of the type of the `new_child` node, or if the node to append is one of this node's ancestors.
400
+
- `WRONG_DOCUMENT_ERR`: Raised if `new_child` was created from a different document than the one that created this node.
401
+
- `NO_MODIFICATION_ALLOWED_ERR`: Raised if this node is readonly.
402
+
"""
403
+
# `HIERARCHY_REQUEST_ERR` should be checked on subclasses by overriding.
# Otherwise, simply append `new_child` using the methods of `NodeList(list)`.
422
+
self.child_nodes.append(new_child)
423
+
new_child._set_parent_node(self)
424
+
returnnew_child
425
+
426
+
defhas_child_nodes(self) ->bool:
427
+
"""This is a convenience method to allow easy determination of whether a node has any children.
428
+
429
+
Returns:
430
+
`True` if the node has any children, `False` if the node has no children.
431
+
"""
432
+
returnbool(self.child_nodes)
433
+
434
+
defclone_node(self, deep: bool=False) ->_AnyNode:
435
+
"""Returns a duplicate of this node.
436
+
437
+
i.e., serves as a generic copy constructor for nodes. The duplicate node has no parent (parentNode returns `None`.).
438
+
Cloning an `Element` copies all attributes and their values, including those generated by the XML processor to represent defaulted attributes, but this method does not copy any text it contains unless it is a deep clone, since the text is contained in a child `Text` node.
439
+
Cloning any other type of node simply returns a copy of this node.
440
+
441
+
Args:
442
+
deep: If `True`, recursively clone the subtree under the specified node; if `False`, clone only the node itself (and its attributes, if it is an `Element`).
0 commit comments