String HEADER_TAG="<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ;
String ROOT_TAG_NAME="Example";
String TAG_START_FRIST="<";
String TAG_START_END=">";
String TAG_END_FRIST="</";
String TAG_END_END=">" ;
String TAG_NAME_ARRAY[]={
"No","City","State"
};
String TAG_VALUE[]={
"1","kolkata","West bengal",
"2","delhi","Delhi",
"3","pune","Maharastra",
"4","bengalor","AP","5","mumbai"
};
in your main use this
String returnXML;
------------------- returnXML=myXMLCreator(ROOT_TAG_NAME,TAG_NAME_ARRAY,TAG_VALUE);
=======================================================================
Use this mathod and paraMeterPass Value from the main
private String myXMLCreator(String mROOT_TAG_NAME,String mTAG_NAME_ARRAY[],String mTAG_VALUE[]) {
if((mTAG_VALUE.length)%(mTAG_NAME_ARRAY.length)!=0)
{
int rem;
rem=(mTAG_VALUE.length)%(mTAG_NAME_ARRAY.length);
String msg=" tag name array and value array not same ";
Log.v(" ERROR ",msg);
}
String XMLString=HEADER_TAG+"\n"+
TAG_START_FRIST+mROOT_TAG_NAME+TAG_START_END+"\n";
for(int i=0,j=0;j<mTAG_VALUE.length;i++,j++)
{
XMLString=XMLString+TAG_START_FRIST+mTAG_NAME_ARRAY[i]+TAG_START_END;
XMLString=XMLString+mTAG_VALUE[j];
XMLString=XMLString+TAG_END_FRIST+mTAG_NAME_ARRAY[i]+TAG_END_END+" \n ";
if(i==2){
i=-1; // one array store all data and tag have three
}
// after 3 time change value from the 0
}
XMLString=XMLString+TAG_END_FRIST+ROOT_TAG_NAME+TAG_END_END;
return XMLString;
}