Contents Up Previous Next

wxXmlNode

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

wxXmlDocument, wxXmlProperty

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::IsWhitespaceOnly
wxXmlNode::RemoveChild
wxXmlNode::SetChildren
wxXmlNode::SetContent
wxXmlNode::SetName
wxXmlNode::SetNext
wxXmlNode::SetParent
wxXmlNode::SetProperties
wxXmlNode::SetType
wxXmlNode::operator=


wxXmlNode::wxXmlNode

wxXmlNode(wxXmlNode* parent, wxXmlNodeType type, const wxString& name, const wxString& content = wxEmptyString, wxXmlProperty* props = NULL, wxXmlNode* next = NULL)

Parameters

parent

type name content props next

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::~wxXmlNode

~wxXmlNode()

The virtual destructor. Deletes attached children and properties.


wxXmlNode::AddChild

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.


wxXmlNode::AddProperty

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.


wxXmlNode::DeleteProperty

bool DeleteProperty(const wxString& name)

Removes the first properties which has the given name from the list of properties for this node.


wxXmlNode::GetChildren

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.


wxXmlNode::GetContent

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.


wxXmlNode::GetDepth

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).


wxXmlNode::GetNodeContent

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.


wxXmlNode::GetName

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

wxXmlNode* GetNext() const

Returns a pointer to the sibling of this node or NULL if there are no siblings.


wxXmlNode::GetParent

wxXmlNode* GetParent() const

Returns a pointer to the parent of this node or NULL if this node has no parent.


wxXmlNode::GetPropVal

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.


wxXmlNode::GetProperties

wxXmlProperty * GetProperties() const

Return a pointer to the first property of this node.


wxXmlNode::GetType

wxXmlNodeType GetType() const

Returns the type of this node.


wxXmlNode::HasProp

bool HasProp(const wxString& propName) const

Returns true if this node has a property named propName.


wxXmlNode::InsertChild

bool InsertChild(wxXmlNode* child, wxXmlNode* before_node)

Inserts the child node after before_node in the children list. If before_node is NULL, then child is prepended to the list of children and becomes the first child of this node. Returns true if before_node has been found and the child node has been inserted.


wxXmlNode::IsWhitespaceOnly

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.


wxXmlNode::RemoveChild

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.


wxXmlNode::SetChildren

void SetChildren(wxXmlNode* child)

Sets as first child the given node. The caller is responsible to delete any previously present children node.


wxXmlNode::SetContent

void SetContent(const wxString& con)

Sets the content of this node.


wxXmlNode::SetName

void SetName(const wxString& name)

Sets the name of this node.


wxXmlNode::SetNext

void SetNext(wxXmlNode* next)

Sets as sibling the given node. The caller is responsible to delete any previously present sibling node.


wxXmlNode::SetParent

void SetParent(wxXmlNode* parent)

Sets as parent the given node. The caller is responsible to delete any previously present parent node.


wxXmlNode::SetProperties

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.


wxXmlNode::SetType

void SetType(wxXmlNodeType type)

Sets the type of this node.


wxXmlNode::operator=

wxXmlNode& operator=(const wxXmlNode& node)

See the copy constructor for more info.