senjuhashirama / pugixml

Automatically exported from code.google.com/p/pugixml
0 stars 0 forks source link

Clone node #177

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am trying to clone the node. not appending that clonned node.
Just copying. But it fails. It is copying the node, but when i try to update 
the clonned node it is updating the source node also.
Following code I am using:
CXmlNode
{
pugi::xml_node m_XmlNode;
}
Clone(const CXmlNode& sourceNode)
{
   pugi::xml_node tempNode;
   const pugi::char_t* nodeName;
   std::auto_ptr<ILog> log(new MockLog());

   CXmlNode newNode(*log);
   pugi::xml_node* newXmlNode = new pugi::xml_node;

   memcpy(&newNode, &sourceNode,sizeof(sourceNode));
   newXmlNode = &newNode.m_XmlNode;
   m_XmlNode = *newXmlNode;

   if(NULL == m_XmlNode)
   {
       return error;
   }
   return OK;
}

other than memcpy() i tried following code also but same output.

m_XmlNode = sourceNode.m_XmlNode;

Please help me

Original issue reported on code.google.com by kshitija...@gmail.com on 26 Sep 2012 at 12:07

GoogleCodeExporter commented 9 years ago
Issue 178 has been merged into this issue.

Original comment by arseny.k...@gmail.com on 26 Sep 2012 at 4:05

GoogleCodeExporter commented 9 years ago
It is impossible to get a unattached node. Every live node object has to be 
appended to some other node in a document. This is because the document manages 
the memory for all nodes in it. So you have to pick your target node first, and 
then do append_copy/append_child and work from there.

Original comment by arseny.k...@gmail.com on 26 Sep 2012 at 4:16

GoogleCodeExporter commented 9 years ago

Original comment by arseny.k...@gmail.com on 29 Sep 2012 at 5:58