Using xml Syntax Highlighting
- - <root>
- <work>
- <taskid taskid="1" />
- <time time="10.10 am" />
- <description description="bapu nagar jaipur" />
- </work>
- <work>
- <taskid taskid="2" />
- <time time="1.25 pm" />
- <description description="raja park jaipur" />
- </work>
- </root>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
Using java Syntax Highlighting
- package com.example;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.Date;
- import javax.xml.parsers.ParserConfigurationException;
- import javax.xml.parsers.SAXParser;
- import javax.xml.parsers.SAXParserFactory;
- import org.xml.sax.InputSource;
- import org.xml.sax.SAXException;
- import org.xml.sax.XMLReader;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.Display;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.AdapterView;
- import android.widget.ArrayAdapter;
- import android.widget.ImageButton;
- import android.widget.LinearLayout;
- import android.widget.ListView;
- import android.widget.TextView;
- import android.widget.AdapterView.OnItemClickListener;
- public class GetItDoneCalender extends Activity {
- TextView datetxt;
- AlertDialog alrt;
- String currentDate;
- ListView timetasklist;
- LinearLayout ll;
- private int month;
- private int year;
- private int date;
- private String myList[];
- ImageButton nextDate;
- ImageButton previousDate;
- private String totalDate;
- Date dt;
- private AlertDialog show;
- private GetItDoneCalender local;
- CalenderDataParsed cdp;
- Display getOrient;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.calender);
- local = this;
- datetxt = (TextView) findViewById(R.id.datetxt);
- timetasklist = (ListView) findViewById(R.id.timetasklist);
- nextDate = (ImageButton) findViewById(R.id.nextCalButton);
- previousDate = (ImageButton) findViewById(R.id.prevCalButton);
- ll = (LinearLayout) findViewById(R.id.lineartasklayout);
- dt = new Date();
- date = dt.getDate();
- month = 1 + dt.getMonth();
- year = 1900 + dt.getYear();
- totalDate = date + "-" + month + "-" + year;
- datetxt.setText(totalDate);
- passTheDate(totalDate);
- nextDate.setOnClickListener(new OnClickListener() {
- public void onClick(View args0) {
- if (month == 1 || month == 3 || month == 5 || month == 7
- || month == 8 || month == 10 || month == 12) {
- if (date < 31) {
- date++;
- } else {
- date = 1;
- if (month < 12) {
- month++;
- } else {
- month = 1;
- year++;
- }
- }
- } else if (month == 4 || month == 6 || month == 9
- || month == 11) {
- if (date < 30) {
- date = date + 1;
- } else {
- date = 1;
- if (month < 12) {
- month++;
- } else {
- month = 1;
- year++;
- }
- }
- } else {
- if (year % 4 == 0) {
- if (date < 29) {
- date++;
- } else {
- date = 1;
- if (month < 12) {
- month++;
- } else {
- month = 1;
- year++;
- }
- }
- } else {
- if (date < 28) {
- date++;
- } else {
- date = 1;
- if (month < 12) {
- month++;
- } else {
- month = 1;
- year++;
- }
- }
- }
- }
- totalDate = date + "-" + month + "-" + year;
- datetxt.setText(totalDate);
- passTheDate(totalDate);
- }
- });
- previousDate.setOnClickListener(new OnClickListener() {
- public void onClick(View args0) {
- if (month == 2 || month == 4 || month == 6 || month == 9
- || month == 11 || month == 1) {
- if (date > 1) {
- date--;
- } else {
- date = 31;
- if (month > 1) {
- month--;
- } else {
- month = 12;
- year--;
- }
- }
- } else if (month == 5 || month == 7 || month == 8
- || month == 10 || month == 12) {
- if (date > 1) {
- date--;
- } else {
- date = 30;
- if (month > 1) {
- month--;
- } else {
- month = 12;
- year--;
- }
- }
- } else {
- if ((year - 1) % 4 != 0) {
- if (date > 1) {
- date--;
- } else {
- date = 28;
- if (month > 1) {
- month--;
- } else {
- month = 12;
- year--;
- }
- }
- } else {
- if (date > 1) {
- date--;
- } else {
- date = 29;
- if (month > 1) {
- month--;
- } else {
- month = 12;
- year--;
- }
- }
- }
- }
- totalDate = date + "-" + month + "-" + year;
- datetxt.setText(totalDate);
- passTheDate(totalDate);
- }
- });
- }
- public void passTheDate(String myDate) {
- currentDate = myDate;
- URL url = null;
- try {
- url = new URL(
- "C:/Documents and Settings/ayush/Desktop/GetItDone Dummy/working.xml");
- // url = new
- // URL("http://www.anddev.org/images/tut/basic/parsingxml/example.xml");
- } catch (MalformedURLException e1) {
- show = new AlertDialog.Builder(local).setTitle("welcome")
- .setMessage(e1.getMessage()).show();
- }
- SAXParserFactory spf = SAXParserFactory.newInstance();
- SAXParser sp = null;
- XMLReader xr = null;
- try {
- sp = spf.newSAXParser();
- } catch (ParserConfigurationException e) {
- show = new AlertDialog.Builder(local).setTitle("welcome")
- .setMessage(e.getMessage()).show();
- } catch (SAXException e) {
- show = new AlertDialog.Builder(local).setTitle("welcome")
- .setMessage(e.getMessage()).show();
- }
- try {
- xr = sp.getXMLReader();
- } catch (SAXException e) {
- show = new AlertDialog.Builder(local).setTitle("welcome")
- .setMessage(e.getMessage()).show();
- }
- CalenderHandler calhldr = new CalenderHandler();
- // ExerciseHandler calhldr=new ExerciseHandler();
- xr.setContentHandler(calhldr);
- try {
- xr.parse(new InputSource(url.openStream()));
- } catch (IOException e) {
- // show=new
- // AlertDialog.Builder(local).setTitle("welcome").setMessage(e.getMessage()).show();
- } catch (SAXException e) {
- show = new AlertDialog.Builder(local).setTitle("welcome")
- .setMessage(e.getMessage()).show();
- }
- /*CalenderDataParsed*/ cdp = calhldr.getParsedData();
- // ParsedData cdp= calhldr.getParsedData();
- int workCount;
- workCount = cdp.totalWorkCount();
- myList = new String[workCount];
- String str = null;
- for (int i = 0; i < myList.length; i++) {
- try {
- getOrient = getWindowManager().getDefaultDisplay();
- if(getOrient.getWidth() <= getOrient.getHeight())
- {
- if(cdp.toString().length()<35)
- {
- myList[i] = cdp.toString();
- }
- else
- {
- myList[i]=cdp.toString().substring(0, 35)+"...";
- }
- }
- else
- {
- if(cdp.toString().length()<52)
- {
- myList[i] = cdp.toString();
- }
- else
- {
- myList[i]=cdp.toString().substring(0, 52)+"...";
- }
- }
- } catch (Exception e) {
- show = new AlertDialog.Builder(local).setTitle("welcome")
- .setMessage("hello " + e.getMessage()).show();
- }
- }
- // String[] myList = new String[]
- // {"Hello","Sapple","System","we ","gonna","take","over","apple","cmpny"};
- timetasklist = new ListView(this);
- timetasklist.setAdapter(new ArrayAdapter<String>(this,
- android.R.layout.simple_list_item_1,myList));
- ll.addView(timetasklist);
- timetasklist.setOnItemClickListener(new OnItemClickListener() {
- public void onItemClick(AdapterView adapterView, View view,
- int position, long id) {
- // SimpleAdapter adapter = (SimpleAdapter)
- // adapterView.getAdapter();
- // show = new AlertDialog.Builder(local).setTitle("welcome")
- // .setMessage("you have clicked on " + currentDate+"at the position "+position).show();
- Intent myIntent = new Intent(view.getContext(), JobOption.class);
- Bundle b=new Bundle();
- b.putString("Date",currentDate);
- b.putString("Time",cdp.extractedTime);
- b.putString("Destination",cdp.extractedDescription);
- b.putInt("TaskID", cdp.extractedTaskId);
- myIntent.putExtras(b);
- startActivityForResult(myIntent, 0);
- }
- });
- }
- }
Parsed in 0.025 seconds, using GeSHi 1.0.8.4
the second class is
Using java Syntax Highlighting
- package com.example;
- import org.xml.sax.Attributes;
- import org.xml.sax.SAXException;
- import org.xml.sax.helpers.DefaultHandler;
- public class CalenderHandler extends DefaultHandler {
- private boolean in_work = false;
- private boolean in_time = false;
- private boolean in_des = false;
- private boolean in_root = false;
- private boolean in_taskid = false;
- private int totalworktags = 0;
- private int taskid;
- private CalenderDataParsed parsdata = new CalenderDataParsed();
- public CalenderDataParsed getParsedData() {
- return this.parsdata;
- }
- public void startDocument() throws SAXException {
- this.parsdata = new CalenderDataParsed();
- }
- public void endDocument() throws SAXException {
- parsdata.setExtractedTotalWorkCount(totalworktags);
- }
- public void startElement(String namespaceURI, String localName,
- String qName, Attributes atts) throws SAXException {
- if (localName.equals("root")) {
- this.in_root = true;
- totalworktags++;
- }
- else if (localName.equals("work")) {
- this.in_work = true;
- } else if (localName.equals("taskid")) {
- this.in_taskid = true;
- String task_id = atts.getValue("taskid");
- taskid = Integer.parseInt(task_id);
- parsdata.setExtractedTaskId(taskid);
- } else if (localName.equals("time")) {
- this.in_time = true;
- String attrValue = atts.getValue("time");
- parsdata.setExtractedTime(attrValue);
- } else if (localName.equals("description")) {
- this.in_des = true;
- String attrValue = atts.getValue("description");
- parsdata.setExtractedDescription(attrValue);
- }
- }
- public void endElement(String namespaceURI, String localName, String qName)
- throws SAXException {
- if (localName.equals("root")) {
- this.in_root = false;
- }
- else if (localName.equals("work")) {
- this.in_work = false;
- }
- else if (localName.equals("taskid")) {
- this.in_taskid = false;
- } else if (localName.equals("time")) {
- this.in_time = false;
- } else if (localName.equals("description")) {
- this.in_des = false;
- }
- }
- public void characters(char ch[], int start, int length) {
- if (this.in_des) {
- parsdata.setExtractedDescription(new String(ch, start, length));
- }
- }
- }
Parsed in 0.014 seconds, using GeSHi 1.0.8.4
the third class contain getter and setter
Using java Syntax Highlighting
- package com.example;
- public class CalenderDataParsed {
- public String extractedDescription;
- public String extractedTime;
- public int extractedTotalWorkCount ;
- public int extractedTaskId;
- public int getExtractedTotalWorkCount() {
- return extractedTotalWorkCount;
- }
- public void setExtractedTotalWorkCount(int extractedTotalWorkCount) {
- this.extractedTotalWorkCount = extractedTotalWorkCount;
- }
- public String getExtractedDescription() {
- return extractedDescription;
- }
- public void setExtractedDescription(String extractedDescription) {
- this.extractedDescription = extractedDescription;
- }
- public String getExtractedTime() {
- return extractedTime;
- }
- public void setExtractedTime(String extractedTime) {
- this.extractedTime = extractedTime;
- }
- public int getExtractedTaskId() {
- return extractedTaskId;
- }
- public void setExtractedTaskId(int extractedTaskId) {
- this.extractedTaskId = extractedTaskId;
- }
- public int totalWorkCount() {
- return this.extractedTotalWorkCount;
- }
- public String toString() {
- return this.extractedTime + "\n" + this.extractedDescription;
- }
- }
Parsed in 0.011 seconds, using GeSHi 1.0.8.4
i want to get the data of all the work tags which are present in this file.