Code example for StringWriter

Methods: toString

0
	private String serialize(Element e, int intent){
		 
		try{ 
		 
			XmlSerializer s = Xml.newSerializer();
			StringWriter sw = new StringWriter();
		 
			s.setOutput(sw);
			s.startDocument("utf-8", null);
			 
			String spaces = null;
			if(intent > 0){
				char[] chars = new char[intent];
				Arrays.fill(chars, ' ');
				spaces = new String(chars);
			} 
			 
			serialize(root, s, 0, spaces);
			s.endDocument();
			 
			return sw.toString();
		}catch(Exception ex){
			ex.printStackTrace();
		} 
		 
		return null;