Code example for XmlSerializer

Methods: endTag, startTag, text

0
	public void write(Song song) throws IOException{
		write(new Song[]{song});
	} 
	 
	private void writeSong(Song sg) throws IOException{
		serializer.startTag("", "song");
		 
		writeXmlTag("id", String.valueOf(sg.getId()));
		writeXmlTag("name", sg.getName());
		writeXmlTag("author", sg.getAuthor());
		writeXmlTag("duration",String.valueOf(sg.getDuration()));
		writeXmlTag("difficulty", String.valueOf(sg.getDifficulty().ordinal()));
		writeXmlTag("temp", String.valueOf(sg.getTemp()));
		serializer.endTag("", "song");
	} 
	 
	public void close() throws IOException{ 
		serializer.endDocument();
		osw.close();
	} 
	 
	public void writeMelody(Song sg) throws IOException{
		serializer.startTag("", "melodis");
		for(int i = 0; i < Song.NOTES_COUNT; i++){
			writeMelody(sg.getDrumMelodyById(i), i);
		} 
		serializer.endTag("", "melody");
	} 
	 
	private void writeMelody(short[] melody, int number) 
			throws  IOException{ 
		serializer.startTag("", "melody");
		serializer.attribute("", "number", String.valueOf(number));
		 
		for(int j =0; j < melody.length; j++){
			serializer.text(String.valueOf(melody[j]) + " ");
		} 
		serializer.endTag("", "melodis");
	} 
	 
	 
	private void writeXmlTag(String tagName, String tagValue) throws IOException{
		serializer.startTag("", tagName);
		serializer.text(tagValue);
		serializer.endTag("", tagName);
	} 
}