Code example for Element

Methods: getChild, setEndElementListener

0
	public List<Track> parse() {
		final Track currentTrack = new Track();
		final List<Track> tracks = new ArrayList<Track>();
		RootElement root = new RootElement(NAMESPACE, "playlist");
		Element trackList = root.getChild(NAMESPACE, "trackList");
		Element track = trackList.getChild(NAMESPACE, "track");
 
		 
		track.setEndElementListener(new EndElementListener() {
			public void end() { 
				tracks.add(currentTrack.copy());
				currentTrack.clear();
			} 
		}); 
		track.getChild(NAMESPACE, "title").setEndTextElementListener(new EndTextElementListener(){
			public void end(String body) {
				currentTrack.setTitle(Html.fromHtml(body).toString());
			} 
		}); 
		track.getChild(NAMESPACE, "creator").setEndTextElementListener(new EndTextElementListener(){
			public void end(String body) {
				currentTrack.setCreator(Html.fromHtml(body).toString());
			} 
		}); 
		track.getChild(NAMESPACE, "album").setEndTextElementListener(new EndTextElementListener(){
			public void end(String body) {
				currentTrack.setAlbum(Html.fromHtml(body).toString());
			} 
		}); 
		track.getChild(NAMESPACE, "annotation").setEndTextElementListener(new EndTextElementListener(){
			public void end(String body) {
				currentTrack.setAnnotation(Html.fromHtml(body).toString());
			} 
		}); 
		track.getChild(NAMESPACE, "duration").setEndTextElementListener(new EndTextElementListener(){
			public void end(String body) {
				currentTrack.setDuration(Html.fromHtml(body).toString());
			} 
		}); 
		track.getChild(NAMESPACE, "info").setEndTextElementListener(new EndTextElementListener(){
			public void end(String body) {
				currentTrack.setInfo(Html.fromHtml(body).toString());
			} 
		}); 
		track.getChild(NAMESPACE, "song-id").setEndTextElementListener(new EndTextElementListener(){
			public void end(String body) {
				currentTrack.setSongId(Html.fromHtml(body).toString());
			} 
		}); 
		track.getChild(NAMESPACE, "play-datetime").setEndTextElementListener(new EndTextElementListener(){
			public void end(String body) {
				currentTrack.setPlaydate(Html.fromHtml(body).toString());
			} 
		});