#include </home/zeitlin/src/wx/github/interface/wx/xml/xml.h>
Represents a node in an XML document.
See wxXmlDocument.
Node has a name and may have content and attributes.
Most common node types are wxXML_TEXT_NODE
(name and attributes are irrelevant) and wxXML_ELEMENT_NODE
.
Example: in <title>hi</title>
there is an element with the name title
and irrelevant content and one child of type wxXML_TEXT_NODE
with hi
as content.
The wxXML_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 wxUSE_UNICODE
is 0, all strings are encoded in the encoding given to wxXmlDocument::Load (default is UTF-8).
Public Member Functions | |
wxXmlNode (wxXmlNode *parent, wxXmlNodeType type, const wxString &name, const wxString &content=wxEmptyString, wxXmlAttribute *attrs=NULL, wxXmlNode *next=NULL, int lineNo=-1) | |
Creates this XML node and eventually insert it into an existing XML tree. | |
wxXmlNode (wxXmlNodeType type, const wxString &name, const wxString &content=wxEmptyString, int lineNo=-1) | |
A simplified version of the first constructor form, assuming a NULL parent. | |
wxXmlNode (const wxXmlNode &node) | |
Copy constructor. | |
virtual | ~wxXmlNode () |
The virtual destructor. | |
virtual void | AddAttribute (const wxString &name, const wxString &value) |
Appends a attribute with given name and value to the list of attributes for this node. | |
virtual void | AddAttribute (wxXmlAttribute *attr) |
Appends given attribute to the list of attributes for this node. | |
virtual void | AddChild (wxXmlNode *child) |
Adds node child as the last child of this node. | |
virtual bool | DeleteAttribute (const wxString &name) |
Removes the first attributes which has the given name from the list of attributes for this node. | |
bool | GetAttribute (const wxString &attrName, wxString *value) const |
Returns true if a attribute named attrName could be found. | |
wxString | GetAttribute (const wxString &attrName, const wxString &defaultVal=wxEmptyString) const |
Returns the value of the attribute named attrName if it does exist. | |
wxXmlAttribute * | GetAttributes () const |
Return a pointer to the first attribute of this node. | |
wxXmlNode * | GetChildren () const |
Returns the first child of this node. | |
const wxString & | GetContent () const |
Returns the content of this node. | |
int | GetDepth (wxXmlNode *grandparent=NULL) const |
Returns the number of nodes which separate this node from grandparent . | |
bool | GetNoConversion () const |
Returns a flag indicating whether encoding conversion is necessary when saving. | |
int | GetLineNumber () const |
Returns line number of the node in the input XML file or -1 if it is unknown. | |
const wxString & | GetName () const |
Returns the name of this node. | |
wxXmlNode * | GetNext () const |
Returns a pointer to the sibling of this node or NULL if there are no siblings. | |
wxString | GetNodeContent () const |
Returns the content of the first child node of type wxXML_TEXT_NODE or wxXML_CDATA_SECTION_NODE . | |
wxXmlNode * | GetParent () const |
Returns a pointer to the parent of this node or NULL if this node has no parent. | |
wxXmlNodeType | GetType () const |
Returns the type of this node. | |
bool | HasAttribute (const wxString &attrName) const |
Returns true if this node has a attribute named attrName. | |
virtual bool | InsertChild (wxXmlNode *child, wxXmlNode *followingNode) |
Inserts the child node immediately before followingNode in the children list. | |
virtual bool | InsertChildAfter (wxXmlNode *child, wxXmlNode *precedingNode) |
Inserts the child node immediately after precedingNode in the children list. | |
bool | IsWhitespaceOnly () const |
Returns true if the content of this node is a string containing only whitespaces (spaces, tabs, new lines, etc). | |
virtual bool | RemoveChild (wxXmlNode *child) |
Removes the given node from the children list. | |
void | SetAttributes (wxXmlAttribute *attr) |
Sets as first attribute the given wxXmlAttribute object. | |
void | SetChildren (wxXmlNode *child) |
Sets as first child the given 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. | |
void | SetNoConversion (bool noconversion) |
Sets a flag to indicate whether encoding conversion is necessary when saving. | |
void | SetParent (wxXmlNode *parent) |
Sets as parent the given node. | |
void | SetType (wxXmlNodeType type) |
Sets the type of this node. | |
wxXmlNode & | operator= (const wxXmlNode &node) |
See the copy constructor for more info. |
wxXmlNode::wxXmlNode | ( | wxXmlNode * | parent, |
wxXmlNodeType | type, | ||
const wxString & | name, | ||
const wxString & | content = wxEmptyString , |
||
wxXmlAttribute * | attrs = NULL , |
||
wxXmlNode * | next = NULL , |
||
int | lineNo = -1 |
||
) |
Creates this XML node and eventually insert it into an existing XML tree.
parent | The parent node to which append this node instance. If this argument is NULL 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 | One of the wxXmlNodeType enumeration value. |
name | The name of the node. This is the string which appears between angular brackets. |
content | The content of the node. Only meaningful when type is wxXML_TEXT_NODE or wxXML_CDATA_SECTION_NODE . |
attrs | If not NULL, this wxXmlAttribute object and its eventual siblings are attached to the node. |
next | If not NULL, this node and its eventual siblings are attached to the node. |
lineNo | Number of line this node was present at in input file or -1. |
wxXmlNode::wxXmlNode | ( | wxXmlNodeType | type, |
const wxString & | name, | ||
const wxString & | content = wxEmptyString , |
||
int | lineNo = -1 |
||
) |
A simplified version of the first constructor form, assuming a NULL parent.
type | One of the wxXmlNodeType enumeration value. |
name | The name of the node. This is the string which appears between angular brackets. |
content | The content of the node. Only meaningful when type is wxXML_TEXT_NODE or wxXML_CDATA_SECTION_NODE . |
lineNo | Number of line this node was present at in input file or -1. |
wxXmlNode::wxXmlNode | ( | const wxXmlNode & | node | ) |
Copy constructor.
Note that this does NOT copy siblings 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 attributes.
virtual wxXmlNode::~wxXmlNode | ( | ) | [virtual] |
The virtual destructor.
Deletes attached children and attributes.
Appends a attribute with given name and value to the list of attributes for this node.
virtual void wxXmlNode::AddAttribute | ( | wxXmlAttribute * | attr | ) | [virtual] |
Appends given attribute to the list of attributes for this node.
virtual void wxXmlNode::AddChild | ( | wxXmlNode * | child | ) | [virtual] |
Adds node child as the last child of this node.
virtual bool wxXmlNode::DeleteAttribute | ( | const wxString & | name | ) | [virtual] |
Removes the first attributes which has the given name from the list of attributes for this node.
Returns true if a attribute named attrName could be found.
The value of that attribute is saved in value (which must not be NULL).
wxString wxXmlNode::GetAttribute | ( | const wxString & | attrName, |
const wxString & | defaultVal = wxEmptyString |
||
) | const |
Returns the value of the attribute named attrName if it does exist.
If it does not exist, the defaultVal is returned.
wxXmlAttribute* wxXmlNode::GetAttributes | ( | ) | const |
Return a pointer to the first attribute of this node.
wxXmlNode* 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.
const wxString& wxXmlNode::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 wxXmlNode::GetDepth | ( | wxXmlNode * | grandparent = NULL | ) | const |
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 NULL node (which is the parent of non-linked nodes or the parent of a wxXmlDocument's root element node).
int wxXmlNode::GetLineNumber | ( | ) | const |
Returns line number of the node in the input XML file or -1
if it is unknown.
const wxString& wxXmlNode::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* wxXmlNode::GetNext | ( | ) | const |
Returns a pointer to the sibling of this node or NULL if there are no siblings.
bool wxXmlNode::GetNoConversion | ( | ) | const |
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.
wxString wxXmlNode::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 "tagnametagcontent/tagname"
is represented by expat with the following tag tree:
wxXML_ELEMENT_NODE name="tagname", content="" |-- wxXML_TEXT_NODE name="", content="tagcontent"
or eventually:
wxXML_ELEMENT_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* wxXmlNode::GetParent | ( | ) | const |
Returns a pointer to the parent of this node or NULL if this node has no parent.
wxXmlNodeType wxXmlNode::GetType | ( | ) | const |
Returns the type of this node.
bool wxXmlNode::HasAttribute | ( | const wxString & | attrName | ) | const |
Returns true if this node has a attribute named attrName.
Inserts the child node immediately before followingNode in the children list.
Inserts the child node immediately after precedingNode in the children list.
child | The child to insert. |
precedingNode | The node to insert child after. As a special case, this can be NULL if this node has no children yet -- in that case, child will become this node's only child node. |
bool wxXmlNode::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.
virtual bool wxXmlNode::RemoveChild | ( | wxXmlNode * | child | ) | [virtual] |
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.
void wxXmlNode::SetAttributes | ( | wxXmlAttribute * | attr | ) |
Sets as first attribute the given wxXmlAttribute object.
The caller is responsible for deleting any previously present attributes attached to this node.
void wxXmlNode::SetChildren | ( | wxXmlNode * | child | ) |
Sets as first child the given node.
The caller is responsible for deleting any previously present children node.
void wxXmlNode::SetContent | ( | const wxString & | con | ) |
Sets the content of this node.
void wxXmlNode::SetName | ( | const wxString & | name | ) |
Sets the name of this node.
void wxXmlNode::SetNext | ( | wxXmlNode * | next | ) |
Sets as sibling the given node.
The caller is responsible for deleting any previously present sibling node.
void wxXmlNode::SetNoConversion | ( | bool | 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.
void wxXmlNode::SetParent | ( | wxXmlNode * | parent | ) |
Sets as parent the given node.
The caller is responsible for deleting any previously present parent node.
void wxXmlNode::SetType | ( | wxXmlNodeType | type | ) |
Sets the type of this node.