Node interfaces/classes¶
-
class
wdom.node.
AbstractNode
(*args, **kwargs)[source]¶ Bases:
xml.dom.Node
Abstract Base Class for Node classes.
-
class
wdom.node.
Node
(parent=None)[source]¶ Bases:
wdom.node.AbstractNode
Base Class for Node interface.
Initialize node object with parent node.
Parameters: parent (Node) – parent node. -
connected
¶ When this instance has any connection, return True.
Return type: bool
-
length
¶ Return number of child nodes.
Return type: int
-
parentNode
¶ Return parent node.
If this node does not have a parent, return
None
.Return type: Optional
[AbstractNode
]
-
childNodes
¶ Return child nodes of this node.
Returned object is an instance of NodeList, which is a list like object but not support any modification. NodeList is a live object, which means that changes on this node is reflected to the object.
Return type: NodeList
[]
-
firstChild
¶ Return the first child node.
If this node does not have any child, return
None
.Return type: Optional
[AbstractNode
]
-
lastChild
¶ Return the last child node.
If this node does not have any child, return
None
.Return type: Optional
[AbstractNode
]
-
previousSibling
¶ Return the previous sibling of this node.
If there is no previous sibling, return
None
.Return type: Optional
[AbstractNode
]
-
nextSibling
¶ Return the next sibling of this node.
If there is no next sibling, return
None
.Return type: Optional
[AbstractNode
]
-
ownerDocument
¶ Return the owner document of this node.
Owner document is an ancestor document node of this node. If this node (or node tree including this node) is not appended to any document node, this property returns
None
.Return type: Document or None
-
appendChild
(node)[source]¶ Append the node at the last of this child nodes.
Return type: AbstractNode
-
index
(node)[source]¶ Return index of the node.
If the node is not a child of this node, raise
ValueError
.Return type: int
-
insertBefore
(node, ref_node)[source]¶ Insert a node just before the reference node.
Return type: AbstractNode
-
hasChildNodes
()[source]¶ Return True if this node has child nodes, otherwise return False.
Return type: bool
-
removeChild
(node)[source]¶ Remove a node from this node.
If node is not a child of this node, raise
ValueError
.Return type: AbstractNode
-
replaceChild
(new_child, old_child)[source]¶ Replace an old child with new child.
Return type: AbstractNode
-
cloneNode
(deep=False)[source]¶ Return new copy of this node.
If optional argument
deep
is specified and is True, new node has clones of child nodes of this node (if presents).Return type: AbstractNode
-
empty
()[source]¶ [Not Standard] Remove all child nodes from this node.
This is equivalent to
node.textContent = ''
.Return type: None
-
textContent
¶ Return text contents of this node and all chid nodes.
When any value is set to this property, all child nodes are removed and new value is set as a text node.
Return type: str
-
-
class
wdom.node.
Text
(text='', parent=None)[source]¶ Bases:
wdom.node.CharacterData
Node class to wrap text contents.
-
html
¶ Return html-escaped string representation of this node.
Return type: str
-
-
class
wdom.node.
RawHtml
(text='', parent=None)[source]¶ Bases:
wdom.node.Text
Very similar to
Text
class, but contents are always not escaped.This node is [NOT DOM Standard].
-
html
¶ Return html representation.
Return type: str
-
-
class
wdom.node.
Comment
(text='', parent=None)[source]¶ Bases:
wdom.node.CharacterData
Comment node class.
-
html
¶ Return html representation.
Return type: str
-
-
class
wdom.node.
DocumentType
(type='html', parent=None)[source]¶ Bases:
wdom.node.Node
,wdom.node.NonDocumentTypeChildNode
DocumentType node class.
Initialize DocumentType node with type doctype.
-
nodeName
¶ Return node name (=type).
Return type: str
-
name
¶ Return node type.
Return type: str
-
html
¶ Return html representation.
Return type: str
-
-
class
wdom.node.
DocumentFragment
(parent=None)[source]¶ Bases:
wdom.node.Node
,wdom.node.ParentNode
DocumentFragument node class.
Initialize node object with parent node.
Parameters: parent (Node) – parent node. -
html
¶ Return html representation.
Return type: str
-
Conclete HTML Elements¶
Node Collectoin Classes¶
-
class
wdom.node.
NodeList
(nodes)[source]¶ Bases:
typing.Sequence
Collection of Node objects.
Initialize NodeList by iterable nodes.
-
length
¶ Return number of nodes in this list.
Return type: int
-
Abstract classes¶
-
class
wdom.node.
ParentNode
(*args, **kwargs)[source]¶ Bases:
wdom.node.AbstractNode
Mixin class for Node classes which can have child nodes.
This class is inherited by Document, DocumentFragment, and Element class.
-
firstElementChild
¶ First Element child node.
If this node has no element child, return None.
Return type: Optional
[AbstractNode
]
-
lastElementChild
¶ Last Element child node.
If this node has no element child, return None.
Return type: Optional
[AbstractNode
]
-
getElementsBy
(cond)[source]¶ Return list of child nodes which matches
cond
.cond
must be a function which gets a single argumentElement
, and returns bool. If the node matches requested condition,cond
should return True. This searches all child nodes recursively.Parameters: cond – Callable[[Element], bool] Return type: NodeList[Element]
-
getElementsByClassName
(class_name)[source]¶ Get child nodes which has
class_name
class attribute.Return type: NodeList
[]
-
query
(relativeSelectors)[source]¶ Not Implemented.
Return type: AbstractNode
-
querySelector
(selectors)[source]¶ Not Implemented.
Return type: AbstractNode
-
-
class
wdom.node.
NonDocumentTypeChildNode
(*args, **kwargs)[source]¶ Bases:
wdom.node.AbstractNode
Mixin class for
CharacterData
andDocumentType
class.-
previousElementSibling
¶ Previous Element Node.
If this node has no previous element node, return None.
Return type: Optional
[AbstractNode
]
-
nextElementSibling
¶ Next Element Node.
If this node has no next element node, return None.
Return type: Optional
[AbstractNode
]
-
-
class
wdom.node.
ChildNode
(*args, **kwargs)[source]¶ Bases:
wdom.node.AbstractNode
Mixin class for Node classes which can have parent node.
This class is inherited by DocumentType, Element, and CharacterData (super class of Text, Comment, and RawHtml) classes.
-
before
(*nodes)[source]¶ Insert nodes before this node.
If nodes contains
str
, it will be converted to Text node.Return type: None
-
after
(*nodes)[source]¶ Append nodes after this node.
If nodes contains
str
, it will be converted to Text node.Return type: None
-
-
class
wdom.node.
CharacterData
(text='', parent=None)[source]¶ Bases:
wdom.node.Node
,wdom.node.ChildNode
,wdom.node.NonDocumentTypeChildNode
Abstract class for classes which wraps text data.
This class is a super class of
Text
andComment
.-
html
¶ Return html representation of this node.
Return type: str
-
length
¶ Return length of content.
Return type: int
-
replaceData
(offset, count, string)[source]¶ Replace data from offset to count by string.
Return type: None
-