Represents a node in an XML
document.
See wx.xml.XmlDocument.
Node has a name and may have content and attributes.
Most common node types are XML_TEXT_NODE
(name and attributes are irrelevant) and XML_ELEMENT_NODE
.
Example: in <title>hi</title>
there is an element with the name title
and irrelevant content and one child of type XML_TEXT_NODE
with hi
as content.
The XML_PI_NODE
type sets the name to the PI
target and the contents to the instructions. Note that whilst the PI
instructions are often in the form of pseudo-attributes these do not use the nodes attribute system. It is the users responsibility to code and decode the instruction text.
If USE_UNICODE
is 0, all strings are encoded in the encoding given to wx.xml.XmlDocument.Load
(default is UTF-8
).
See also
Creates this |
|
Appends a attribute with given name and value to the list of attributes for this node. |
|
Adds node child as the last child of this node. |
|
Removes the first attributes which has the given name from the list of attributes for this node. |
|
Returns the value of the attribute named attrName if it does exist. |
|
Return a pointer to the first attribute of this node. |
|
Returns the first child of this node. |
|
Returns the content of this node. |
|
Returns the number of nodes which separate this node from |
|
Returns line number of the node in the input |
|
Returns the name of this node. |
|
Returns a pointer to the sibling of this node or |
|
Returns a flag indicating whether encoding conversion is necessary when saving. |
|
Returns the content of the first child node of type |
|
Returns a pointer to the parent of this node or |
|
Returns the type of this node. |
|
Returns |
|
Inserts the child node immediately before followingNode in the children list. |
|
Inserts the child node immediately after precedingNode in the children list. |
|
Returns |
|
Removes the given node from the children list. |
|
Sets the content of this node. |
|
Sets the name of this node. |
|
Sets as sibling the given node. |
|
Sets a flag to indicate whether encoding conversion is necessary when saving. |
|
Sets as parent the given node. |
|
Sets the type of this node. |
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
wx.xml.
XmlNode
(object)¶Possible constructors:
XmlNode(parent, type, name, content="", attrs=None, next=None,
lineNo=-1)
XmlNode(type, name, content="", lineNo=-1)
XmlNode(node)
Represents a node in an XML
document.
__init__
(self, *args, **kw)¶__init__ (self, parent, type, name, content=””, attrs=None, next=None, lineNo=-1)
Creates this XML
node and eventually insert it into an existing XML
tree.
parent (wx.xml.XmlNode) – The parent node to which append this node instance. If this argument is None
this new node will be floating and it can be appended later to another one using the AddChild
or InsertChild
functions. Otherwise the child is already added to the XML
tree by this constructor and it shouldn’t be done again.
type (XmlNodeType) – One of the wx.xml.XmlNodeType enumeration value.
name (string) – The name of the node. This is the string which appears between angular brackets.
content (string) – The content of the node. Only meaningful when type is XML_TEXT_NODE
or XML_CDATA_SECTION_NODE
.
attrs (wx.xml.XmlAttribute) – If not None
, this wx.xml.XmlAttribute object and its eventual siblings are attached to the node.
next (wx.xml.XmlNode) – If not None
, this node and its eventual siblings are attached to the node.
lineNo (int) – Number of line this node was present at in input file or -1.
__init__ (self, type, name, content=””, lineNo=-1)
A simplified version of the first constructor form, assuming a None
parent.
type (XmlNodeType) – One of the wx.xml.XmlNodeType enumeration value.
name (string) – The name of the node. This is the string which appears between angular brackets.
content (string) – The content of the node. Only meaningful when type is XML_TEXT_NODE
or XML_CDATA_SECTION_NODE
.
lineNo (int) – Number of line this node was present at in input file or -1.
__init__ (self, node)
Copy constructor.
Note that this does NOT copy siblings and parent pointer, i.e. GetParent
and GetNext
will return None
after using copy constructor and are never unmodified by operator=
. On the other hand, it DOES copy children and attributes.
node (wx.xml.XmlNode) –
AddAttribute
(self, *args, **kw)¶AddAttribute (self, name, value)
Appends a attribute with given name and value to the list of attributes for this node.
name (string) –
value (string) –
AddAttribute (self, attr)
Appends given attribute to the list of attributes for this node.
attr (wx.xml.XmlAttribute) –
AddChild
(self, child)¶Adds node child as the last child of this node.
child (wx.xml.XmlNode) –
Note
Note that this function works in O(n) time where n is the number of existing children. Consequently, adding large number of child nodes using this method can be expensive, because it has O(n^2) time complexity in number of nodes to be added. Use InsertChildAfter
to populate XML
tree in linear time.
See also
DeleteAttribute
(self, name)¶Removes the first attributes which has the given name from the list of attributes for this node.
name (string) –
bool
GetAttribute
(self, attrName, defaultVal="")¶Returns the value of the attribute named attrName if it does exist.
If it does not exist, the defaultVal is returned.
attrName (string) –
defaultVal (string) –
string
GetAttributes
(self)¶Return a pointer to the first attribute of this node.
GetChildren
(self)¶Returns the first child of this node.
To get a pointer to the second child of this node (if it does exist), use the GetNext
function on the returned value.
GetContent
(self)¶Returns the content of this node.
Can be an empty string. Be aware that for nodes of type XML_ELEMENT_NODE
(the most used node type) the content is an empty string. See GetNodeContent
for more details.
string
GetDepth
(self, grandparent=None)¶Returns the number of nodes which separate this node from grandparent
.
This function searches only the parents of this node until it finds grandparent or the None
node (which is the parent of non-linked nodes or the parent of a wx.xml.XmlDocument’s root element node).
grandparent (wx.xml.XmlNode) –
int
GetLineNumber
(self)¶Returns line number of the node in the input XML
file or -1
if it is unknown.
int
GetName
(self)¶Returns the name of this node.
Can be an empty string (e.g. for nodes of type XML_TEXT_NODE
or XML_CDATA_SECTION_NODE
).
string
GetNext
(self)¶Returns a pointer to the sibling of this node or None
if there are no siblings.
GetNoConversion
(self)¶Returns a flag indicating whether encoding conversion is necessary when saving.
The default is False
.
You can improve saving efficiency considerably by setting this value.
bool
GetNodeContent
(self)¶Returns the content of the first child node of type XML_TEXT_NODE
or XML_CDATA_SECTION_NODE
.
This function is very useful since the XML
snippet "tagnametagcontent/tagname"
is represented by expat with the following tag tree:
XML_ELEMENT_NODE name="tagname", content=""
|-- XML_TEXT_NODE name="", content="tagcontent"
or eventually:
XML_ELEMENT_NODE name="tagname", content=""
|-- XML_CDATA_SECTION_NODE name="", content="tagcontent"
An empty string is returned if the node has no children of type XML_TEXT_NODE
or XML_CDATA_SECTION_NODE
, or if the content of the first child of such types is empty.
string
GetParent
(self)¶Returns a pointer to the parent of this node or None
if this node has no parent.
GetType
(self)¶Returns the type of this node.
HasAttribute
(self, attrName)¶Returns True
if this node has a attribute named attrName.
attrName (string) –
bool
InsertChild
(self, child, followingNode)¶Inserts the child node immediately before followingNode in the children list.
child (wx.xml.XmlNode) –
followingNode (wx.xml.XmlNode) –
bool
True
if followingNode has been found and the child node has been inserted.
Note
For historical reasons, followingNode may be None
. In that case, then child is prepended to the list of children and becomes the first child of this node, i.e. it behaves identically to using the first children (as returned by GetChildren
) for followingNode).
See also
InsertChildAfter
(self, child, precedingNode)¶Inserts the child node immediately after precedingNode in the children list.
child (wx.xml.XmlNode) – The child to insert.
precedingNode (wx.xml.XmlNode) – The node to insert child after. As a special case, this can be None
if this node has no children yet child will become this node’s only child node.
bool
True
if precedingNode has been found and the child node has been inserted.
New in version 2.8.8.
See also
IsWhitespaceOnly
(self)¶Returns True
if the content of this node is a string containing only whitespaces (spaces, tabs, new lines, etc).
Note that this function is locale-independent since the parsing of XML
documents must always produce the exact same tree regardless of the locale it runs under.
bool
RemoveChild
(self, child)¶Removes the given node from the children list.
Returns True
if the node was found and removed or False
if the node could not be found. Note that the caller is responsible for deleting the removed node in order to avoid memory leaks.
child (wx.xml.XmlNode) –
bool
SetContent
(self, con)¶Sets the content of this node.
con (string) –
SetName
(self, name)¶Sets the name of this node.
name (string) –
SetNext
(self, next)¶Sets as sibling the given node.
The caller is responsible for deleting any previously present sibling node.
next (wx.xml.XmlNode) –
SetNoConversion
(self, noconversion)¶Sets a flag to indicate whether encoding conversion is necessary when saving.
The default is False
.
You can improve saving efficiency considerably by setting this value.
noconversion (bool) –
SetParent
(self, parent)¶Sets as parent the given node.
The caller is responsible for deleting any previously present parent node.
parent (wx.xml.XmlNode) –
SetType
(self, type)¶Sets the type of this node.
type (XmlNodeType) –
Attributes
¶See GetAttributes
Children
¶See GetChildren
Content
¶See GetContent
and SetContent
LineNumber
¶See GetLineNumber
NoConversion
¶See GetNoConversion
and SetNoConversion
NodeContent
¶See GetNodeContent