Problem changing attribute value

34 views
Skip to first unread message

aryajur

unread,
May 27, 2010, 12:31:36 AM5/27/10
to TinyXML++
Hi,
I am using tinyXML to process a bunch of XML files. I want to read an
XML file then process it like delete some elements, change the value
of some attributes and then write to a different file. I am doing
something like this:


TiXmlElement *pElement;
TiXmlNode *newNode=0;
newNode = sourceXMLNode->Clone();
pElement = newNode->ToElement();
TiXmlAttribute* pAttrib=pElement->FirstAttribute();
while (pAttrib)
{
if(StringToUpper(pAttrib->Name())=="MY_ATTRIBUTE")
{
pAttrib->SetValue("H0");
}

pAttrib=pAttrib->Next();
}
destXMLNode->LinkEndChild(pElement);


So here I am making a copy of sourceXMLNode and then search for
attribute named MY_ATTRIBUTE and then change its value. And then add
this copied node to destXMLNode. But in the end when I write the
destXMLNode to a file it doesn't show the changed value, it shows the
old value that was present in sourceXML.


But if I don't make a clone and just use sourceXMLNode pick the
element from it and change he attribute value and then write the
sourceXMLNode I see the changed value.

Why does making a clone not change the value in destXMLNode??

Does anybody have any idea why that might be happenning. Any help or
suggestions would be greatly appreciated.

Reply all
Reply to author
Forward
0 new messages