I've a small problem concerning reading / appending to a document.
I've an existing TiXmlDocument, and get (socket transfer) another XML file, which i need to append in a special part in the tree.
Currently, i'm using another document to parse the incoming string, appending it to the "real" document.
Now, i have a memory leak everyone knows: I append the RootNode to the "real" document. The temporary document still exists. Now, when i delete the temporary document, i destroy the real document tree. When i dont delete the temporary document, i have created a new memory leak...
Any suggestions?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This basically works. It detaches any node in the tree (till now quite properly as far as i could test that). So i can just link the node i get returned (the node which got detached of the other document) to my 2nd doc.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
TiXmlDocument *doc = new TiXmlDocument();
TiXmlNode *response = doc->LinkEndChild (new TiXmlElement ("response"));
response->ToElement()->SetAttribute ("type", "save");
response->ToElement()->SetAttribute ("requestid", requestid);
TiXmlNode *status = response->LinkEndChild (new TiXmlElement ("status"));
status->LinkEndChild (new TiXmlText ("OK"));
TiXmlNode* pageid = response->LinkEndChild (new TiXmlElement ("pageid"));
pageid->ToElement()->SetAttribute("old",pageID);
pageid->ToElement()->SetAttribute("db",lastid);
TiXmlDocument *tmpdoc = new TiXmlDocument();
tmpdoc->Parse (x.c_str());
if (string(tmpdoc->RootElement()->FirstChild("status")->FirstChild()->Value()) != "failed")
{
pageid->LinkEndChild (tmpdoc->RootElement()->FirstChild("status")->NextSibling("articleid")->Detach());
delete tmpdoc;
}
-----------------------
TiXmlNode* TiXmlNode::Detach()
{
if (next)
next->prev = prev;
if (prev)
prev->next = next;
if (parent->FirstChild() == this)
parent->firstChild=next;
return this;
}
-------------
Basically, i need to delete a party of the document i get back from tmpstr, since i dont want to append all the document. So i need to detach it, deleting new document.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everyone.
I've a small problem concerning reading / appending to a document.
I've an existing TiXmlDocument, and get (socket transfer) another XML file, which i need to append in a special part in the tree.
Currently, i'm using another document to parse the incoming string, appending it to the "real" document.
Now, i have a memory leak everyone knows: I append the RootNode to the "real" document. The temporary document still exists. Now, when i delete the temporary document, i destroy the real document tree. When i dont delete the temporary document, i have created a new memory leak...
Any suggestions?
In between i have implemented the following experimental function:
void TiXmlNode::Detach()
{
next->prev = prev;
prev->next = next;
return this;
}
This basically works. It detaches any node in the tree (till now quite properly as far as i could test that). So i can just link the node i get returned (the node which got detached of the other document) to my 2nd doc.
Can you reproduce/show the problem in a small block of code?
Cheers
Ellers
TiXmlDocument *doc = new TiXmlDocument();
TiXmlNode *response = doc->LinkEndChild (new TiXmlElement ("response"));
response->ToElement()->SetAttribute ("type", "save");
response->ToElement()->SetAttribute ("requestid", requestid);
TiXmlNode *status = response->LinkEndChild (new TiXmlElement ("status"));
status->LinkEndChild (new TiXmlText ("OK"));
TiXmlNode* pageid = response->LinkEndChild (new TiXmlElement ("pageid"));
pageid->ToElement()->SetAttribute("old",pageID);
pageid->ToElement()->SetAttribute("db",lastid);
TiXmlDocument *tmpdoc = new TiXmlDocument();
tmpdoc->Parse (x.c_str());
if (string(tmpdoc->RootElement()->FirstChild("status")->FirstChild()->Value()) != "failed")
{
pageid->LinkEndChild (tmpdoc->RootElement()->FirstChild("status")->NextSibling("articleid")->Detach());
delete tmpdoc;
}
-----------------------
TiXmlNode* TiXmlNode::Detach()
{
if (next)
next->prev = prev;
if (prev)
prev->next = next;
if (parent->FirstChild() == this)
parent->firstChild=next;
return this;
}
-------------
Basically, i need to delete a party of the document i get back from tmpstr, since i dont want to append all the document. So i need to detach it, deleting new document.