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
hasAttributes()[source]

Return True if this node has attributes.

Return type:bool
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
item(index)[source]

Return item with the index.

If the index is negative number or out of the list, return None.

Return type:Optional[Node]
index(node)[source]

Get index of the node.

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.

children

Return list of child nodes.

Currently this is not a live object.

Return type:NodeList[]
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]
prepend(*nodes)[source]

Insert new nodes before first child node.

Return type:None
append(*nodes)[source]

Append new nodes after last child node.

Return type:None
getElementsBy(cond)[source]

Return list of child nodes which matches cond.

cond must be a function which gets a single argument Element, 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]
getElementsByTagName(tag)[source]

Get child nodes which tag name is tag.

Return type:NodeList[]
getElementsByClassName(class_name)[source]

Get child nodes which has class_name class attribute.

Return type:NodeList[]
query(relativeSelectors)[source]

Not Implemented.

Return type:AbstractNode
queryAll(relativeSelectors)[source]

Not Implemented.

Return type:NodeList[]
querySelector(selectors)[source]

Not Implemented.

Return type:AbstractNode
querySelectorAll(selectors)[source]

Not Implemented.

Return type:NodeList[]
class wdom.node.NonDocumentTypeChildNode(*args, **kwargs)[source]

Bases: wdom.node.AbstractNode

Mixin class for CharacterData and DocumentType 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
replaceWith(*nodes)[source]

Replace this node with nodes.

If nodes contains str, it will be converted to Text node.

Return type:None
remove()[source]

Remove this node from the parent 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 and Comment.

html

Return html representation of this node.

Return type:str
length

Return length of content.

Return type:int
appendData(string)[source]

Add string to end of this node.

Return type:None
insertData(offset, string)[source]

Insert string at offset on this node.

Return type:None
deleteData(offset, count)[source]

Delete data by offset to count letters.

Return type:None
replaceData(offset, count, string)[source]

Replace data from offset to count by string.

Return type:None
childNodes

Return child nodes.

This node can’t have child, so return empty NodeList object.

Return type:NodeList[]
appendChild(node)[source]

Not supported.

Return type:Node
insertBefore(node, ref_node)[source]

Not supported.

Return type:Node
hasChildNodes()[source]

Return false.

Return type:bool
removeChild(node)[source]

Not supported.

Return type:Node
replaceChild(new_child, old_child)[source]

Not supported.

Return type:Node
hasAttributes()[source]

Return false.

Return type:bool

WdomElement class (base class of Tag)