[xml] Adding a node..



I have a function to work with a configuration file called XML_Add_Key(char *Key). Key is a semi-colon delimited list of the keys, like key1;key2;key3 would be: Ok.. Thats fine, I have a semi-recursive routine that seems to add everything correctly, BUT, when it writes it out, it is the original file.. No changes.. Here is the function, basically, you can skip down to the key... Thats where the search and replace is.. bool XML_Add_Key(char *key) { sprintf(tmpstr,"Entering XML_Add_key(%s).",key); logger(tmpstr,0); // Lets see if the Key already exists if(XML_Key_Exists(key)) { sprintf(tmpstr,"%s already exists.",key); logger(tmpstr,0); return(true); } // Ok, first we have to get our keys.. We will allow 16 levels deep. Key_Struct Keys[16]; char *TOKEN=new char[128]; char *tmpkey=new char[1024]; strcpy(tmpkey,key); int a=0; int TotalKeys=0; TOKEN=strtok(tmpkey,";"); while(TOKEN!=NULL) { strcpy(Keys[TotalKeys].Name,upcase(TOKEN)); TotalKeys++; TOKEN=strtok(NULL,";"); } delete(TOKEN); delete(tmpkey); //Ok we have our keys.. Now lets find everything.. xmlDocPtr doc; xmlNodePtr cur,prev; xmlChar *xmlkey; doc=xmlParseFile(CONFIG_FILE); if(doc==NULL) { sprintf(tmpstr,"Cannot open configuration file: %s.",CONFIG_FILE); logger(tmpstr,1); a=0; sprintf(tmpstr,"Exiting XML_Add_Key(%s), rc==FALSE.",key); logger(tmpstr,0); return(false); } int KeyCount; KeyCount=0; cur=xmlDocGetRootElement(doc); cur=cur->xmlChildrenNode; while(KeyCount<=TotalKeys) { if((!xmlStrcmp(cur->name,(const xmlChar *)Keys[KeyCount].Name))) { KeyCount++; cur=cur->xmlChildrenNode; } if(cur->next==NULL) { cur=xmlNewTextChild(cur,NULL,(xmlChar *)Keys[KeyCount].Name,NULL); int res; res=xmlSaveFile(CONFIG_FILE,doc); KeyCount++; } else { cur=cur->next; } } } Any suggestions as to why this does not work, pls email me.


Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]