How to convert string in to xml in android?
I am in need to convert data in List to XML string. Currently i am using the following method as conversion method in android, 

      private String writeXml(List<DataItem> item)
	   {

	    XmlSerializer serializer = Xml.newSerializer();
	    StringWriter writer = new StringWriter();
	    try {
	        serializer.setOutput(writer);
	        serializer.startDocument("UTF-16",null);
	        serializer.startTag("", "MainData"); 
	        serializer.startTag("", "Data"); 
	        for (DataItem in: item)
	        	{ 
	            serializer.startTag("", "Key");
	            serializer.text(in.getKey());
	            serializer.endTag("", "Key");
	            serializer.startTag("", "Value");
	            serializer.text(in.getValue());
	            serializer.endTag("", "Value");  
	            }

	        serializer.endTag("", "Data");
	        serializer.endTag("", "MainData");
	        serializer.endDocument();

	        System.out.println(writer.toString());
	        return writer.toString();
	        
	    } catch (Exception e) {
	        throw new RuntimeException(e);
	    }
	}
	
I have seen this method in C# 
     

            XmlSerializer serializer = new XmlSerializer(typeof(List<DataItem>));
			StringWriter sw = new StringWriter();
			
			XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
			ns.Add("","");
			serializer.Serialize(sw, tempdataitems,ns);
					
			form.AddField("EX" + i ,  sw.ToString());


But while trying this it shows  

          Syntax error on token ">", Expression expected after this token

at the end of 

          new XmlSerializer(typeof(List<DataItem>));


Is it possible to have the same method in android? or
Is there any other method to do the same conversion?

Thanks in advance


How to convert string in to xml in android?
===

I am in need to convert data in List to XML string. Currently i am using the following method as conversion method in android, 

      private String writeXml(List<DataItem> item)
	   {

	    XmlSerializer serializer = Xml.newSerializer();
	    StringWriter writer = new StringWriter();
	    try {
	        serializer.setOutput(writer);
	        serializer.startDocument("UTF-16",null);
	        serializer.startTag("", "MainData"); 
	        serializer.startTag("", "Data"); 
	        for (DataItem in: item)
	        	{ 
	            serializer.startTag("", "Key");
	            serializer.text(in.getKey());
	            serializer.endTag("", "Key");
	            serializer.startTag("", "Value");
	            serializer.text(in.getValue());
	            serializer.endTag("", "Value");  
	            }

	        serializer.endTag("", "Data");
	        serializer.endTag("", "MainData");
	        serializer.endDocument();

	        System.out.println(writer.toString());
	        return writer.toString();
	        
	    } catch (Exception e) {
	        throw new RuntimeException(e);
	    }
	}
	
I have seen this method in C# 
     

            XmlSerializer serializer = new XmlSerializer(typeof(List<DataItem>));
			StringWriter sw = new StringWriter();
			
			XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
			ns.Add("","");
			serializer.Serialize(sw, tempdataitems,ns);
					
			form.AddField("EX" + i ,  sw.ToString());


But while trying this it shows  

          Syntax error on token ">", Expression expected after this token

at the end of 

          new XmlSerializer(typeof(List<DataItem>));


Is it possible to have the same method in android? or
Is there any other method to do the same conversion?

Thanks in advance

