Node has a name and may have content and attributes.
Most common node types are @c wxXML_TEXT_NODE (name and attributes are irrelevant)
- and @c wxXML_ELEMENT_NODE (e.g. in @c \<title\>hi\</title\> there is an element
- with name="title", irrelevant content and one child @c wxXML_TEXT_NODE
- with content="hi").
+ and @c wxXML_ELEMENT_NODE.
+
+ Example: in <tt>\<title\>hi\</title\></tt> there is an element with the name
+ @c title and irrelevant content and one child of type @c wxXML_TEXT_NODE
+ with @c hi as content.
If @c wxUSE_UNICODE is 0, all strings are encoded in the encoding given to
wxXmlDocument::Load (default is UTF-8).
/**
The virtual destructor. Deletes attached children and attributes.
*/
- ~wxXmlNode();
+ virtual ~wxXmlNode();
/**
Appends a attribute with given @a name and @a value to the list of
attributes for this node.
*/
- void AddAttribute(const wxString& name, const wxString& value);
+ virtual void AddAttribute(const wxString& name, const wxString& value);
/**
Appends given attribute to the list of attributes for this node.
*/
- void AddAttribute(wxXmlAttribute* attr);
+ virtual void AddAttribute(wxXmlAttribute* attr);
/**
Adds node @a child as the last child of this node.
@see InsertChild(), InsertChildAfter()
*/
- void AddChild(wxXmlNode* child);
+ virtual void AddChild(wxXmlNode* child);
/**
Removes the first attributes which has the given @a name from the list of
attributes for this node.
*/
- bool DeleteAttribute(const wxString& name);
+ virtual bool DeleteAttribute(const wxString& name);
/**
Returns true if a attribute named attrName could be found.
Be aware that for nodes of type @c wxXML_ELEMENT_NODE (the most used node type)
the content is an empty string. See GetNodeContent() for more details.
*/
- wxString GetContent() const;
+ const wxString& GetContent() const;
/**
Returns the number of nodes which separe this node from @c grandparent.
Can be an empty string (e.g. for nodes of type @c wxXML_TEXT_NODE or
@c wxXML_CDATA_SECTION_NODE).
*/
- wxString GetName() const;
+ const wxString& GetName() const;
/**
Returns a pointer to the sibling of this node or @NULL if there are no
@see AddChild(), InsertChildAfter()
*/
- bool InsertChild(wxXmlNode* child, wxXmlNode* followingNode);
+ virtual bool InsertChild(wxXmlNode* child, wxXmlNode* followingNode);
/**
Inserts the @a child node immediately after @a precedingNode in the
@return @true if @a precedingNode has been found and the @a child
node has been inserted.
+ @param child
+ The child to insert.
@param precedingNode
The node to insert @a child after. As a special case, this can be
@NULL if this node has no children yet -- in that case, @a child
@see InsertChild(), AddChild()
*/
- bool InsertChildAfter(wxXmlNode* child, wxXmlNode* precedingNode);
+ virtual bool InsertChildAfter(wxXmlNode* child, wxXmlNode* precedingNode);
/**
Returns @true if the content of this node is a string containing only
Note that the caller is reponsible for deleting the removed node in order
to avoid memory leaks.
*/
- bool RemoveChild(wxXmlNode* child);
+ virtual bool RemoveChild(wxXmlNode* child);
/**
Sets as first attribute the given wxXmlAttribute object.
Represents a node attribute.
- Example: in @c "\<img src="hello.gif" id="3"/\>", @c "src" is attribute with value
- @c "hello.gif" and @c "id" is a attribute with value @c "3".
+ Example: in <tt>\<img src="hello.gif" id="3"/\></tt>, @c src is an attribute
+ with value @c hello.gif and @c id is an attribute with value @c 3.
@library{wxxml}
@category{xml}
/**
The virtual destructor.
*/
- ~wxXmlAttribute();
+ virtual ~wxXmlAttribute();
/**
Returns the name of this attribute.
@code
wxXmlDocument doc;
- if (!doc.Load(wxT("myfile.xml")))
- return @false;
+ if (!doc.Load("myfile.xml"))
+ return false;
// start processing the XML file
- if (doc.GetRoot()-GetName() != wxT("myroot-node"))
- return @false;
+ if (doc.GetRoot()->GetName() != "myroot-node")
+ return false;
- wxXmlNode *child = doc.GetRoot()-GetChildren();
+ wxXmlNode *child = doc.GetRoot()->GetChildren();
while (child) {
- if (child-GetName() == wxT("tag1")) {
+ if (child->GetName() == "tag1") {
// process text enclosed by tag1/tag1
- wxString content = child-GetNodeContent();
+ wxString content = child->GetNodeContent();
...
// process attributes of tag1
wxString attrvalue1 =
- child-GetAttribute(wxT("attr1"),
- wxT("default-value"));
+ child->GetAttribute("attr1", "default-value");
wxString attrvalue2 =
- child-GetAttribute(wxT("attr2"),
- wxT("default-value"));
+ child->GetAttribute("attr2", "default-value");
...
- } else if (child-GetName() == wxT("tag2")) {
+ } else if (child->GetName() == "tag2") {
// process tag2 ...
}
- child = child-GetNext();
+ child = child->GetNext();
}
@endcode
@code
wxXmlDocument doc;
- doc.Load(wxT("myfile.xml"), wxT("UTF-8"), wxXMLDOC_KEEP_WHITESPACE_NODES);
+ doc.Load("myfile.xml", "UTF-8", wxXMLDOC_KEEP_WHITESPACE_NODES);
// myfile2.xml will be indentic to myfile.xml saving it this way:
- doc.Save(wxT("myfile2.xml"), wxXML_NO_INDENTATION);
+ doc.Save("myfile2.xml", wxXML_NO_INDENTATION);
@endcode
Using default parameters, you will get a reformatted document which in general
@code
wxXmlDocument doc;
- doc.Load(wxT("myfile.xml"));
- doc.Save(wxT("myfile2.xml")); // myfile2.xml != myfile.xml
+ doc.Load("myfile.xml");
+ doc.Save("myfile2.xml"); // myfile2.xml != myfile.xml
@endcode
@library{wxxml}
Loads the given filename using the given encoding. See Load().
*/
wxXmlDocument(const wxString& filename,
- const wxString& encoding = wxT("UTF-8"));
+ const wxString& encoding = "UTF-8"));
/**
Loads the XML document from given stream using the given encoding. See Load().
/**
Virtual destructor. Frees the document root node.
*/
- ~wxXmlDocument();
+ virtual ~wxXmlDocument();
/**
Detaches the document root node and returns it.
@note This is the encoding original file was saved in, @b not the
encoding of in-memory representation!
*/
- wxString GetFileEncoding() const;
+ const wxString& GetFileEncoding() const;
/**
Returns the root node of the document.
If the version attribute was not explicitely given in the header, this function
returns an empty string.
*/
- wxString GetVersion() const;
+ const wxString& GetVersion() const;
/**
Returns @true if the document has been loaded successfully.