I have an Xml.may i know how can i parse it.
i need to get all OfficeName in to an Dictionary/array from the below XML.
eg:
Dictionary[key:tblOffice1]= "!-Everett Corporate Office"
Dictionary[key:tblOffice2]= "!-Fullterton SCE Call Center"
etc..
.
the above thing is not a exact code.
please help me .
my XML is
<DataTable xmlns="http://www.myoffice.com:1212/">
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="tblOffice" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="tblOffice">
<xs:complexType>
<xs:sequence>
<xs:element name="OfficeName" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<DocumentElement xmlns="">
<tblOffice diffgr:id="tblOffice1" msdata:rowOrder="0">
<OfficeName>!-Everett Corporate Office</OfficeName>
</tblOffice>
<tblOffice diffgr:id="tblOffice2" msdata:rowOrder="1">
<OfficeName>!-Fullterton SCE Call Center</OfficeName>
</tblOffice>
<tblOffice diffgr:id="tblOffice3" msdata:rowOrder="2">
<OfficeName>Columbus Office</OfficeName>
</tblOffice>
<tblOffice diffgr:id="tblOffice4" msdata:rowOrder="3">
<OfficeName>Edison Office</OfficeName>
</tblOffice>
<tblOffice diffgr:id="tblOffice5" msdata:rowOrder="4">
<OfficeName>Franklin Office</OfficeName>
</tblOffice>
<tblOffice diffgr:id="tblOffice6" msdata:rowOrder="5">
<OfficeName>Fullterton Office</OfficeName>
</tblOffice>
<tblOffice diffgr:id="tblOffice7" msdata:rowOrder="6">
<OfficeName>Hatfield Office</OfficeName>
</tblOffice>
<tblOffice diffgr:id="tblOffice8" msdata:rowOrder="7">
<OfficeName>Hayward Office</OfficeName>
</tblOffice>
<tblOffice diffgr:id="tblOffice9" msdata:rowOrder="8">
<OfficeName>Las Vegas Office</OfficeName>
</tblOffice>
<tblOffice diffgr:id="tblOffice10" msdata:rowOrder="9">
<OfficeName>Phoenix Office</OfficeName>
</tblOffice>
<tblOffice diffgr:id="tblOffice11" msdata:rowOrder="10">
<OfficeName>Portland Office</OfficeName>
</tblOffice>
<tblOffice diffgr:id="tblOffice12" msdata:rowOrder="11">
<OfficeName>Salt Lake Office</OfficeName>
</tblOffice>
<tblOffice diffgr:id="tblOffice13" msdata:rowOrder="12">
<OfficeName>Snohomish Office</OfficeName>
</tblOffice>
<tblOffice diffgr:id="tblOffice14" msdata:rowOrder="13">
<OfficeName>Spokane Office</OfficeName>
</tblOffice>
</DocumentElement>
</diffgr:diffgram>
</DataTable>
may i know , how can i do it.
i wrote the method
package com.timetracker.app;
import java.io.StringReader;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class OfficeLocation extends ListActivity {
private static String SOAP_ACTION = "http://www.myoffice.com:1212/getTTofficeNames";
private static final String METHOD_NAME = "getTTofficeNames";
private static String NAMESPACE = "http://www.markdevweb.com:8082/";
private static String URL = "http://www.markdevweb.com:8082/ttwss/ttadmin.asmx";
ProgressDialog pbd;
TextView tv;
/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// for getting header in the list view
//View offheader = getLayoutInflater().inflate(R.layout.offheader,null);
//ListView listView = getListView();
//listView.addHeaderView(offheader);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
System.out.println("the soap object request in officeloc = " +request);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
System.out.println("the soapserializationenvelope= "+envelope);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
System.out.println("under the request in officeloc");
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
System.out.println("under the url in officeloc");
try{
androidHttpTransport.call(SOAP_ACTION, envelope);
System.out.println("Under the soap action2 in officeloc");
//SoapPrimitive resultString=(SoapPrimitive)envelope.getResponse();
SoapObject resultString=(SoapObject)envelope.getResponse();
System.out.println("the result string displayed ab in officeloc :" +resultString);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput( new StringReader (resultString.toString() ) );
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
System.out.println("Start document");
} else if(eventType == XmlPullParser.START_TAG) {
System.out.println("Start tag "+xpp.getName());
} else if(eventType == XmlPullParser.END_TAG) {
System.out.println("End tag "+xpp.getName());
} else if(eventType == XmlPullParser.TEXT) {
System.out.println("Text "+xpp.getText());
}
eventType = xpp.next();
}
System.out.println("End document");
/* try {
XmlPullParser parsers=new org.kxml2.io.KXmlParser();
parsers.setInput(new java.io.StringReader("<tblOffice><OfficeName>hayword</OfficeName></tblOffice>"));
//parsers.nextTag();
parsers.require(XmlPullParser.START_DOCUMENT, null, null);
parsers.nextTag();
parsers.require(XmlPullParser.START_TAG, null, "tblOffice");
parsers.nextTag();
parsers.require(XmlPullParser.START_TAG, null, "OfficeName");
System.out.println("the elements"+ parsers.getText());
parsers.require(XmlPullParser.END_TAG, null, "OfficeName");
parsers.nextTag();
parsers.require(XmlPullParser.END_TAG, null, "tblOffice");
parsers.nextTag();
parsers.require(XmlPullParser.END_DOCUMENT, null, null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
String result=resultString.toString();
System.out.println("the new value in officeloc "+result);
String[] names = new String[] {result};
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.officelayout,R.id.label, names));
}
catch (Exception e)
{
tv.setText(e.getMessage());
}
// Create an array of Strings, that will be put to our ListActivity
//"Everett","Hayword","SaltLake","Vegas","Snohomish","Hatfield","Bothell"
// Use your own layout and point the adapter to the UI elements which
// contains the label
//with larger size this.setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, names));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Object o = this.getListAdapter().getItem(position);
String keyword = o.toString();
Toast.makeText(OfficeLocation.this, "you have pressed" + keyword+"the position is"+position+"the ID is"+id, Toast.LENGTH_LONG)
.show();
if(position==0)
{
Context localContext1 = this.getApplicationContext();
Intent localIntent1 = new Intent(localContext1, Everett.class);
this.startActivity(localIntent1);
}
if(position==1)
{
Context localContext2 = this.getApplicationContext();
Intent localIntent2 = new Intent(localContext2, Everett.class);
this.startActivity(localIntent2);
}
if(position==2)
{
Context localContext3 = getApplicationContext();
Intent localIntent3 = new Intent(localContext3, Everett.class);
startActivity(localIntent3);
}
if(position==3)
{
Context localContext4 = getApplicationContext();
Intent localIntent4 = new Intent(localContext4, Everett.class);
startActivity(localIntent4);
}
if(position==4)
{
Context localContext5 = getApplicationContext();
Intent localIntent5 = new Intent(localContext5, Everett.class);
startActivity(localIntent5);
}
if(position==5)
{
Context localContext6 = getApplicationContext();
Intent localIntent6 = new Intent(localContext6, Everett.class);
startActivity(localIntent6);
}
if(position==6)
{
Context localContext7 = getApplicationContext();
Intent localIntent7 = new Intent(localContext7, Everett.class);
startActivity(localIntent7);
}
}
}
However it like I am able to see get in to that method. of webservice.
and able to see the whole page I am not able to filter it out by line by line.
Its like a list of values.. but comming as the page as a whole
I guess what you need here is XPath, should be something like that, not tested though:
More info about XPath in android: http://developer.android.com/reference/javax/xml/xpath/package-summary.html
Tutorial to get the full power of XPath:
http://www.w3schools.com/xpath/