// And now, I want to change "Tom" to "Jack"
TiXmlText *new_txt = new TiXmlText("Jack");
pElm2->LinkEndChild(new_txt);
cout << pElm2->GetText() << endl; // Output is "TomJack"
How to use "Jack" replace "Tom"?
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2010-08-21
void SetNodeValue( TiXmlNode* node , CString value ) {
TiXmlNode* child ;
TiXmlText* text ;
for ( child = node->FirstChild() ; child ; node = child->NextSibling() ) {
text = child->ToText() ;
if ( text ) {
if ( text->Value() != 0 ) {
DeleteNode( text ) ;
break ;
}
}
}
if ( !value.IsEmpty() ) {
child = node->FirstChild() ;
text = new TiXmlText( value ) ;
( child ) ? node->InsertBeforeChild( child , *text ) : node->LinkEndChild( text ) ;
}
Document->SaveFile( File ) ;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I worte following code:
TiXmlElement* pElm = pElm->FirstChildElement("name");
cout << pElm2->GetText() << endl; // It's OK, output is "Tom"
// And now, I want to change "Tom" to "Jack"
TiXmlText *new_txt = new TiXmlText("Jack");
pElm2->LinkEndChild(new_txt);
cout << pElm2->GetText() << endl; // Output is "TomJack"
How to use "Jack" replace "Tom"?
Thanks!
void SetNodeValue( TiXmlNode* node , CString value ) {
TiXmlNode* child ;
TiXmlText* text ;
for ( child = node->FirstChild() ; child ; node = child->NextSibling() ) {
text = child->ToText() ;
if ( text ) {
if ( text->Value() != 0 ) {
DeleteNode( text ) ;
break ;
}
}
}
if ( !value.IsEmpty() ) {
child = node->FirstChild() ;
text = new TiXmlText( value ) ;
( child ) ? node->InsertBeforeChild( child , *text ) : node->LinkEndChild( text ) ;
}
Document->SaveFile( File ) ;
}