Commit e0264b51 authored by SHAILESH KUMAR's avatar SHAILESH KUMAR

toxml.c updated

parent d8d388a4
#include<stdio.h>
#include<string.h>
void fromXML(char *key,char *value,char* messagetype, char *message,char *xml){
strcpy(key,"");
strcpy(value,"");
strcpy(message,"");
strcpy(messagetype,"");
int i;
char tag[50];
char data[300000];
strcpy(data,"");
for(i=0;i<strlen(xml);i++){
if(xml[i]=='<'){
strcpy(tag,"");
}
else if (xml[i]=='>'){
if(tag[0]!='/'){
//do nothing
}
}
else{
char a[2];
a[0]=xml[i];
a[1]='\0';
if(!strcmp(tag,"Key")){
strcat(key,a);
}
else if(!strcmp(tag,"Value")){
strcat(value,a);
}
else if(!strcmp(tag,"Message")){
strcat(message,a);
}
else if(!strcmp(tag,"type")){
if(strcmp(a,"\"") && strcmp(a,"=") )
strcat(messagetype,a);
}
else{
if(xml[i]==' '){
strcpy(tag,"");
}
else{
strcat(tag,a);
}
}
}
}
}
void toXML(char *resp,char key[],char value[],char messagetype[],char message[]){
strcpy(resp,"");
char temp[300000]="";
char *tempo="<?xml version=\"1.0\" encoding=\"UTF-8\"?><KVMessage type=\"";
strcat(temp,tempo);
strcat(temp,messagetype);
strcat(temp,"\">");
if(strcmp(key,"")){
strcat(temp,"<Key>");
strcat(temp,key);
strcat(temp,"</Key>");
if(strcmp(value,"")){
strcat(temp,"<Value>");
strcat(temp,value);
strcat(temp,"</Value>");
}
}
else{
strcat(temp,"<Message>");
strcat(temp,message);
strcat(temp,"</Message>");
}
strcat(temp,"</KVMessage>");
strcat(resp,temp);
}
/*
int main() {
//code
char x[]="hello";
char y[]="world";
char resp[300000];
toXML(resp,x,"","getreq","success");
//printf("%s\n",resp);
strcpy(resp,"");
toXML(resp,x,y,"putreq","success");
char ix[300];
char iy[300000];
char msg[10];
fromXML(ix,iy,msg,resp);
if(strcmp(ix,"")){
printf("key=%s\n",ix);
}
if(strcmp(iy,"")){
printf("value=%s\n",iy);
}
if(strcmp(msg,"")){
printf("msg=%s\n",msg);
}
/*toXML(x,"","delreq","success");
toXML(x,y,"resp","success");
toXML("",y,"resp","success");
toXML("",y,"resp","failure");
toXML(resp,"","","resp","success");
fromXML(ix,iy,msg,resp);
if(strcmp(ix,"")){
printf("key=%s\n",ix);
}
if(strcmp(iy,"")){
printf("value=%s\n",iy);
}
if(strcmp(msg,"")){
printf("msg=%s\n",msg);
}
toXML(resp,"","","resp","success");
fromXML(ix,iy,msg,resp);
if(strcmp(ix,"")){
printf("key=%s\n",ix);
}
if(strcmp(iy,"")){
printf("value=%s\n",iy);
}
if(strcmp(msg,"")){
printf("msg=%s\n",msg);
}
return 0;
}*/
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment