Represents a node in an XML document. See wxXmlDocument.
Node has a name and may have content and properties. Most common node types are wxXML_TEXT_NODE (name and properties are irrelevant) and wxXML_ELEMENT_NODE (e.g. in <title>hi</title> there is an element with name="title", irrelevant content and one child (wxXML_TEXT_NODE with content="hi").
If wxUSE_UNICODE is 0, all strings are encoded in the encoding given to wxXmlDocument::Load (default is UTF-8).
Derived from
No base class
Include files
<wx/xml/xml.h>
Constants
The following are the node types supported by wxXmlNode:
enum wxXmlNodeType
{
wxXML_ELEMENT_NODE,
wxXML_ATTRIBUTE_NODE,
wxXML_TEXT_NODE,
wxXML_CDATA_SECTION_NODE,
wxXML_ENTITY_REF_NODE,
wxXML_ENTITY_NODE,
wxXML_PI_NODE,
wxXML_COMMENT_NODE,
wxXML_DOCUMENT_NODE,
wxXML_DOCUMENT_TYPE_NODE,
wxXML_DOCUMENT_FRAG_NODE,
wxXML_NOTATION_NODE,
wxXML_HTML_DOCUMENT_NODE
}
See also
Members
wxXmlNode::wxXmlNode
wxXmlNode::~wxXmlNode
wxXmlNode::AddChild
wxXmlNode::AddProperty
wxXmlNode::DeleteProperty
wxXmlNode::GetChildren
wxXmlNode::GetContent
wxXmlNode::GetDepth
wxXmlNode::GetNodeContent
wxXmlNode::GetName
wxXmlNode::GetNext
wxXmlNode::GetParent
wxXmlNode::GetPropVal
wxXmlNode::GetProperties
wxXmlNode::GetType
wxXmlNode::HasProp
wxXmlNode::InsertChild
wxXmlNode::InsertChildAfter
wxXmlNode::IsWhitespaceOnly
wxXmlNode::RemoveChild
wxXmlNode::SetChildren
wxXmlNode::SetContent
wxXmlNode::SetName
wxXmlNode::SetNext
wxXmlNode::SetParent
wxXmlNode::SetProperties
wxXmlNode::SetType
wxXmlNode::operator=
wxXmlNode(wxXmlNode* parent, wxXmlNodeType type, const wxString& name, const wxString& content = wxEmptyString, wxXmlProperty* props = NULL, wxXmlNode* next = NULL)
Parameters
parent
wxXmlNode(const wxXmlNode& node)
Copy constructor. Note that this does NOT copy syblings and parent pointer, i.e. GetParent() and GetNext() will return NULL after using copy ctor and are never unmodified by operator=.
On the other hand, it DOES copy children and properties.
wxXmlNode(wxXmlNodeType type, const wxString& name, const wxString& content = wxEmptyString)
A simplified version of the first constructor form.
~wxXmlNode()
The virtual destructor. Deletes attached children and properties.
void AddChild(wxXmlNode* child)
Adds the given node as child of this node. To attach a second children to this node, use the SetNext() function of the child node.
void AddProperty(const wxString& name, const wxString& value)
Appends a property with given name and value to the list of properties for this node.
void AddProperty(wxXmlProperty* prop)
Appends the given property to the list of properties for this node.
bool DeleteProperty(const wxString& name)
Removes the first properties which has the given name from the list of properties for this node.
wxXmlNode* GetChildren() const
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.
wxString GetContent() const
Returns the content of this node. Can be an empty string. Be aware that for nodes of type wxXML_ELEMENT_NODE (the most used node type) the content is an empty string. See GetNodeContent() for more details.
int GetDepth(wxXmlNode* grandparent = NULL) const
Returns the number of nodes which separe this node from grandparent.
This function searches only the parents of this node until it finds grandparent or the NULL node (which is the parent of non-linked nodes or the parent of a wxXmlDocument's root node).
wxString GetNodeContent() const
Returns the content of the first child node of type wxXML_TEXT_NODE or wxXML_CDATA_SECTION_NODE. This function is very useful since the XML snippet "<tagname>tagcontent</tagname>" is represented by expat with the following tag tree:
wxXML_ENTITY_NODE name="tagname", content="" |-- wxXML_TEXT_NODE name="", content="tagcontent"or eventually:
wxXML_ENTITY_NODE name="tagname", content="" |-- wxXML_CDATA_SECTION_NODE name="", content="tagcontent"An empty string is returned if the node has no children of type wxXML_TEXT_NODE or wxXML_CDATA_SECTION_NODE, or if the content of the first child of such types is empty.
wxString GetName() const
Returns the name of this node. Can be an empty string (e.g. for nodes of type wxXML_TEXT_NODE or wxXML_CDATA_SECTION_NODE).
wxXmlNode* GetNext() const
Returns a pointer to the sibling of this node or NULL if there are no siblings.
wxXmlNode* GetParent() const
Returns a pointer to the parent of this node or NULL if this node has no parent.
bool GetPropVal(const wxString& propName, wxString* value) const
Returns true if a property named propName could be found. The value of that property is saved in value (which must not be NULL).
wxString GetPropVal(const wxString& propName, const wxString& defaultVal) const
Returns the value of the property named propName if it does exist. If it does not exist, the defaultVal is returned.
wxXmlProperty * GetProperties() const
Return a pointer to the first property of this node.
wxXmlNodeType GetType() const
Returns the type of this node.
bool HasProp(const wxString& propName) const
Returns true if this node has a property named propName.
bool InsertChild(wxXmlNode* child, wxXmlNode* followingNode)
Inserts the child node immediately before followingNode in the children list. If followingNode is NULL, then child is prepended to the list of children and becomes the first child of this node. Returns true if followingNode has been found and the child node has been inserted.
bool InsertChildAfter(wxXmlNode* child, wxXmlNode* precedingNode)
Inserts the child node immediately after precedingNode in the children list. Returns true if precedingNode has been found and the child node has been inserted.
Parameters
child
This function is new since wxWidgets version 2.8.8
bool IsWhitespaceOnly() const
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(wxXmlNode* 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 reponsible for deleting the removed node in order to avoid memory leaks.
void SetChildren(wxXmlNode* child)
Sets as first child the given node. The caller is responsible to delete any previously present children node.
void SetContent(const wxString& con)
Sets the content of this node.
void SetName(const wxString& name)
Sets the name of this node.
void SetNext(wxXmlNode* next)
Sets as sibling the given node. The caller is responsible to delete any previously present sibling node.
void SetParent(wxXmlNode* parent)
Sets as parent the given node. The caller is responsible to delete any previously present parent node.
void SetProperties(wxXmlProperty* prop)
Sets as first property the given wxXmlProperty object. The caller is responsible to delete any previously present properties attached to this node.
void SetType(wxXmlNodeType type)
Sets the type of this node.
wxXmlNode& operator=(const wxXmlNode& node)
See the copy constructor for more info.