Create a class Webservice.class
package com.example.readingservice;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.net.ParseException;
import android.util.Log;
public class WebService {
SoapObject resultRequestSOAP = null;
final String NAMESPACE = "http://tempuri.org/";
//final String URL = "http://192.168.40.200/MMADTracking/TrackService.svc?wsdl";
final String URL = "http://hotelservices.azurewebsites.net/hotelservice.svc?wsdl";
public SoapPrimitive getMoviesCategory(int id) {
final String SOAP_ACTION="http://tempuri.org/IHotelService/GetGuide";
final String METHOD_NAME ="GetGuide"; //"GetService";//
String result = null ;
SoapPrimitive resultRequestSOAP = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("menuid");
propertyInfo.setValue(id);
propertyInfo.setType(Integer.class);
request.addProperty(propertyInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.encodingStyle = SoapSerializationEnvelope.ENV;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
// SoapObject resultValue = (SoapObject)envelope.bodyIn;
resultRequestSOAP = (SoapPrimitive) envelope.getResponse();
Log.d("Value", ""+resultRequestSOAP);
return resultRequestSOAP;
}catch (Exception aE) {
Log.d("WebActivity GetTrainStatusInfo",""+result );
}
return resultRequestSOAP;
}
public SoapPrimitive getGuide(int id) {
final String SOAP_ACTION="http://tempuri.org/IHotelService/GetGuide";
final String METHOD_NAME = "GetGuide";
String result = null ;
SoapPrimitive resultRequestSOAP = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("menuid");
propertyInfo.setValue(id);
propertyInfo.setType(Integer.class);
request.addProperty(propertyInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.encodingStyle = SoapSerializationEnvelope.ENV;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
// SoapObject resultValue = (SoapObject)envelope.bodyIn;
resultRequestSOAP = (SoapPrimitive) envelope.getResponse();
Log.d("Value", ""+resultRequestSOAP);
return resultRequestSOAP;
}catch (Exception aE) {
Log.d("WebActivity GetTrainStatusInfo",""+result );
}
return resultRequestSOAP;
}
public SoapPrimitive getService(int id) {
final String SOAP_ACTION="http://tempuri.org/IHotelService/GetService";
final String METHOD_NAME = "GetService";
String result = null ;
SoapPrimitive resultRequestSOAP = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("guideId");
propertyInfo.setValue(id);
propertyInfo.setType(Integer.class);
request.addProperty(propertyInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.encodingStyle = SoapSerializationEnvelope.ENV;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
// SoapObject resultValue = (SoapObject)envelope.bodyIn;
resultRequestSOAP = (SoapPrimitive) envelope.getResponse();
Log.d("Value", ""+resultRequestSOAP);
return resultRequestSOAP;
}catch (Exception aE) {
Log.d("WebActivity GetTrainStatusInfo",""+result );
}
return resultRequestSOAP;
}
public SoapPrimitive GetServiceItems(int id) {
final String SOAP_ACTION="http://tempuri.org/IHotelService/GetServiceItems";
final String METHOD_NAME = "GetServiceItems";
String result = null ;
SoapPrimitive resultRequestSOAP = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("serviceid");
propertyInfo.setValue(id);
propertyInfo.setType(Integer.class);
request.addProperty(propertyInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.encodingStyle = SoapSerializationEnvelope.ENV;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
// SoapObject resultValue = (SoapObject)envelope.bodyIn;
resultRequestSOAP = (SoapPrimitive) envelope.getResponse();
Log.d("Value", ""+resultRequestSOAP);
return resultRequestSOAP;
}catch (Exception aE) {
Log.d("WebActivity GetTrainStatusInfo",""+result );
}
return resultRequestSOAP;
}
}
Out put is the xml format which is comming as string eg.
<?xml version="1.0" encoding="utf-8"?><HSOutput status="1">
<Service guide_id="7" service_id="6" service_name="Restaurants" service_imgurl="" insertdate="" username="TAJ" />
<Service guide_id="7" service_id="17" service_name="Fitness centers" service_imgurl="" insertdate="" username="TAJ" />
<Service guide_id="7" service_id="18" service_name="Business Centers" service_imgurl="" insertdate="" username="TAJ" />
<Service guide_id="7" service_id="19" service_name="Leisure " service_imgurl="" insertdate="" username="TAJ" />
<Service guide_id="7" service_id="20" service_name="Weli Deli and Lounge " service_imgurl="" insertdate="" username="TAJ" /></HSOutput>
<?xml version="1.0" encoding="utf-8"?><HSOutput status="1">
<Service service_id="6" serviceitem_id="2" serviceitem_name="Eugenia" serviceitem_imgurl=""
serviceitem_description="Eugenia, the multi-cuisine coffee shop, is open for buffet breakfast,
light snacks, lunch and dinner. Serenaders enhance the ambience of the restaurant. "
serviceitem_availability=" Timings : 0730-2245 hrs." serviceitem_servicetype="" insertdate="" username="" />
<Service service_id="6" serviceitem_id="3" serviceitem_name="Miguel Arcanjo" serviceitem_imgurl=""
serviceitem_description="Miguel Arcanjo, the Mediterranean speciality restaurant, serves authentic Italian, Spanish,
Portuguese and Provencal cuisine. Serenaders enhance the ambience of the restaurant. "
serviceitem_availability="Timings: 1230-1430 hrs for lunch, 1930-2230 hrs for dinner. " serviceitem_servicetype="" insertdate="" username="" />
<Service service_id="6" serviceitem_id="4" serviceitem_name="Alegria" serviceitem_imgurl=""
serviceitem_description="Li Bai, the Oriental speciality restaurant, serves cuisine from Hunan, Sichuan and Canton.
Serenaders enhance the ambience of the restaurant."
serviceitem_availability=" Timings : Lunch 1230-1430 hrs for lunch, " serviceitem_servicetype="" insertdate="" username="" />
<Service service_id="6" serviceitem_id="5" serviceitem_name="Adega Cameons" serviceitem_imgurl=""
serviceitem_description="Alegria, the speciality restaurant, serves coastal and authentic Goan cuisine.
The restaurant exudes an old-world Goan and Portuguese charm. Serenaders enhance the ambience of the restaurant."
serviceitem_availability=" Timings: 1100-2230 hrs." serviceitem_servicetype="" insertdate="" username="" />
<Service service_id="6" serviceitem_id="6" serviceitem_name="Lobster Shack" serviceitem_imgurl=""
serviceitem_description="Lobster Shack, the informal speciality restaurant on the beach front, serves the choicest seafood grills.
Open from October to April." serviceitem_availability=" Timings: 1930-2300 hrs." serviceitem_servicetype="" insertdate="" username="" />
</HSOutput>
Create another class ReadService.class
package com.example.readingservice;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import android.util.Log;
import android.widget.Toast;
public class ReadServices {
Document dest = null;
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser;
WebService webService=new WebService();
String values;
List<ServiceBean> serviceList;
/*
this is the guide list values reffering the Werservice class and listing out all the values
*/
/********************guide list start************************/
public List<Guide> getGuide() {
List<Guide> guideList = new ArrayList<Guide>();
SoapPrimitive soapObject=webService.getGuide(12);
values=soapObject.toString();
if(soapObject !=null){
SoapPrimitive soapObject1=webService.getGuide(12);
String src=soapObject1.toString();
try {
parser = dbFactory.newDocumentBuilder();
dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
NodeList locationNodeList2 = dest.getElementsByTagName("Guide");
if(locationNodeList2 != null && locationNodeList2.getLength() > 0){
for(int i=0;i<locationNodeList2.getLength();i++){
Node locationNode = locationNodeList2.item(i);
NamedNodeMap locNamedNodeMap = locationNode.getAttributes();
String guide_id=locNamedNodeMap.getNamedItem("guide_id").getNodeValue().toString();
String guide_name = locNamedNodeMap.getNamedItem("gudie_name").getNodeValue().toString();
//values=soapObject.toString();
Guide guide = new Guide();
guide.setId(guide_id);
guide.setName(guide_name);
guideList.add(guide);
}
}else{
}
}
return guideList;
}
/********************guide list end************************/
/***********************Service list start******************/
public List<ServiceBean> getService() {
serviceList = new ArrayList<ServiceBean>();
SoapPrimitive soapObject=webService.getService(7);
values=soapObject.toString();
if(soapObject !=null){
try {
parser = dbFactory.newDocumentBuilder();
dest = parser.parse(new ByteArrayInputStream(values.getBytes()));
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
NodeList locationNodeList2 = dest.getElementsByTagName("Service");
if(locationNodeList2 != null && locationNodeList2.getLength() > 0){
for(int i=0;i<locationNodeList2.getLength();i++){
Node locationNode = locationNodeList2.item(i);
NamedNodeMap locNamedNodeMap = locationNode.getAttributes();
String service_id=locNamedNodeMap.getNamedItem("service_id").getNodeValue().toString();
String service_name = locNamedNodeMap.getNamedItem("service_name").getNodeValue().toString();
Log.d("Service Id", service_id+"");
Log.d("Service Name", service_name+"");
values=soapObject.toString();
ServiceBean service = new ServiceBean();
service.setId(service_id);
service.setName(service_name);
serviceList.add(service);
}
Log.d("serviceList",""+serviceList.size());
return serviceList;
}else{
}
}
return serviceList;
}
/***********************Service list end******************/
/***********************ServiceItem list start******************/
public List<ServiceItemBean> getServiceItem() {
List<ServiceItemBean> serviceItemList=new ArrayList<ServiceItemBean>();
SoapPrimitive soapObject=webService.GetServiceItems(6);
values=soapObject.toString();
if(soapObject !=null){
try {
parser = dbFactory.newDocumentBuilder();
dest = parser.parse(new ByteArrayInputStream(values.getBytes()));
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
NodeList locationNodeList2 = dest.getElementsByTagName("Service");
if(locationNodeList2 != null && locationNodeList2.getLength() > 0){
for(int i=0;i<locationNodeList2.getLength();i++){
Node locationNode = locationNodeList2.item(i);
NamedNodeMap locNamedNodeMap = locationNode.getAttributes();
String serviceitem_id=locNamedNodeMap.getNamedItem("serviceitem_id").getNodeValue().toString();
String serviceitem_name=locNamedNodeMap.getNamedItem("serviceitem_name").getNodeValue().toString();
String serviceitem_availability = locNamedNodeMap.getNamedItem("serviceitem_availability").getNodeValue().toString();
String serviceitem_description = locNamedNodeMap.getNamedItem("serviceitem_description").getNodeValue().toString();
values=soapObject.toString();
ServiceItemBean serviceItem = new ServiceItemBean();
serviceItem.setId(Integer.parseInt(serviceitem_id));
serviceItem.setName(serviceitem_name);
serviceItem.setAvialbility(serviceitem_availability);
serviceItem.setDescription(serviceitem_description);
serviceItemList.add(serviceItem);
Log.d("Name :", ""+serviceitem_name);
Log.d("Avail :", ""+serviceitem_availability);
}
}else{
}
}
return serviceItemList;
}
/***********************ServiceItem list start******************/
}
here the method are reading the service which are all in xml string which is converted as invitial variable and paking as list
this can be checked as main activity
package com.example.readingservice;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
WebService webService=new WebService();
TextView tv;
String values;
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
// readServices();
ReadServices readServices=new ReadServices();
//readServices.getGuide();
// Log.d("**my Gude*", ""+readServices.getGuide().size());
//Log.d("**my Service*", ""+readServices.getService().size());
Log.d("My Service Itesm",""+readServices.getServiceItem().size());
//retriving the bean value
List<Guide> guideList=new ArrayList<Guide>();
guideList=readServices.getGuide();
Iterator<Guide> iterator=guideList.iterator();
while (iterator.hasNext()) {
Guide guide=iterator.next();
String name=guide.getName();
Log.d("my bean Value:", ""+name);
}
}
package com.example.readingservice;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.net.ParseException;
import android.util.Log;
public class WebService {
SoapObject resultRequestSOAP = null;
final String NAMESPACE = "http://tempuri.org/";
//final String URL = "http://192.168.40.200/MMADTracking/TrackService.svc?wsdl";
final String URL = "http://hotelservices.azurewebsites.net/hotelservice.svc?wsdl";
public SoapPrimitive getMoviesCategory(int id) {
final String SOAP_ACTION="http://tempuri.org/IHotelService/GetGuide";
final String METHOD_NAME ="GetGuide"; //"GetService";//
String result = null ;
SoapPrimitive resultRequestSOAP = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("menuid");
propertyInfo.setValue(id);
propertyInfo.setType(Integer.class);
request.addProperty(propertyInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.encodingStyle = SoapSerializationEnvelope.ENV;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
// SoapObject resultValue = (SoapObject)envelope.bodyIn;
resultRequestSOAP = (SoapPrimitive) envelope.getResponse();
Log.d("Value", ""+resultRequestSOAP);
return resultRequestSOAP;
}catch (Exception aE) {
Log.d("WebActivity GetTrainStatusInfo",""+result );
}
return resultRequestSOAP;
}
public SoapPrimitive getGuide(int id) {
final String SOAP_ACTION="http://tempuri.org/IHotelService/GetGuide";
final String METHOD_NAME = "GetGuide";
String result = null ;
SoapPrimitive resultRequestSOAP = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("menuid");
propertyInfo.setValue(id);
propertyInfo.setType(Integer.class);
request.addProperty(propertyInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.encodingStyle = SoapSerializationEnvelope.ENV;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
// SoapObject resultValue = (SoapObject)envelope.bodyIn;
resultRequestSOAP = (SoapPrimitive) envelope.getResponse();
Log.d("Value", ""+resultRequestSOAP);
return resultRequestSOAP;
}catch (Exception aE) {
Log.d("WebActivity GetTrainStatusInfo",""+result );
}
return resultRequestSOAP;
}
public SoapPrimitive getService(int id) {
final String SOAP_ACTION="http://tempuri.org/IHotelService/GetService";
final String METHOD_NAME = "GetService";
String result = null ;
SoapPrimitive resultRequestSOAP = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("guideId");
propertyInfo.setValue(id);
propertyInfo.setType(Integer.class);
request.addProperty(propertyInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.encodingStyle = SoapSerializationEnvelope.ENV;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
// SoapObject resultValue = (SoapObject)envelope.bodyIn;
resultRequestSOAP = (SoapPrimitive) envelope.getResponse();
Log.d("Value", ""+resultRequestSOAP);
return resultRequestSOAP;
}catch (Exception aE) {
Log.d("WebActivity GetTrainStatusInfo",""+result );
}
return resultRequestSOAP;
}
public SoapPrimitive GetServiceItems(int id) {
final String SOAP_ACTION="http://tempuri.org/IHotelService/GetServiceItems";
final String METHOD_NAME = "GetServiceItems";
String result = null ;
SoapPrimitive resultRequestSOAP = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("serviceid");
propertyInfo.setValue(id);
propertyInfo.setType(Integer.class);
request.addProperty(propertyInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.encodingStyle = SoapSerializationEnvelope.ENV;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
// SoapObject resultValue = (SoapObject)envelope.bodyIn;
resultRequestSOAP = (SoapPrimitive) envelope.getResponse();
Log.d("Value", ""+resultRequestSOAP);
return resultRequestSOAP;
}catch (Exception aE) {
Log.d("WebActivity GetTrainStatusInfo",""+result );
}
return resultRequestSOAP;
}
}
Out put is the xml format which is comming as string eg.
<?xml version="1.0" encoding="utf-8"?><HSOutput status="1">
<Service guide_id="7" service_id="6" service_name="Restaurants" service_imgurl="" insertdate="" username="TAJ" />
<Service guide_id="7" service_id="17" service_name="Fitness centers" service_imgurl="" insertdate="" username="TAJ" />
<Service guide_id="7" service_id="18" service_name="Business Centers" service_imgurl="" insertdate="" username="TAJ" />
<Service guide_id="7" service_id="19" service_name="Leisure " service_imgurl="" insertdate="" username="TAJ" />
<Service guide_id="7" service_id="20" service_name="Weli Deli and Lounge " service_imgurl="" insertdate="" username="TAJ" /></HSOutput>
<?xml version="1.0" encoding="utf-8"?><HSOutput status="1">
<Service service_id="6" serviceitem_id="2" serviceitem_name="Eugenia" serviceitem_imgurl=""
serviceitem_description="Eugenia, the multi-cuisine coffee shop, is open for buffet breakfast,
light snacks, lunch and dinner. Serenaders enhance the ambience of the restaurant. "
serviceitem_availability=" Timings : 0730-2245 hrs." serviceitem_servicetype="" insertdate="" username="" />
<Service service_id="6" serviceitem_id="3" serviceitem_name="Miguel Arcanjo" serviceitem_imgurl=""
serviceitem_description="Miguel Arcanjo, the Mediterranean speciality restaurant, serves authentic Italian, Spanish,
Portuguese and Provencal cuisine. Serenaders enhance the ambience of the restaurant. "
serviceitem_availability="Timings: 1230-1430 hrs for lunch, 1930-2230 hrs for dinner. " serviceitem_servicetype="" insertdate="" username="" />
<Service service_id="6" serviceitem_id="4" serviceitem_name="Alegria" serviceitem_imgurl=""
serviceitem_description="Li Bai, the Oriental speciality restaurant, serves cuisine from Hunan, Sichuan and Canton.
Serenaders enhance the ambience of the restaurant."
serviceitem_availability=" Timings : Lunch 1230-1430 hrs for lunch, " serviceitem_servicetype="" insertdate="" username="" />
<Service service_id="6" serviceitem_id="5" serviceitem_name="Adega Cameons" serviceitem_imgurl=""
serviceitem_description="Alegria, the speciality restaurant, serves coastal and authentic Goan cuisine.
The restaurant exudes an old-world Goan and Portuguese charm. Serenaders enhance the ambience of the restaurant."
serviceitem_availability=" Timings: 1100-2230 hrs." serviceitem_servicetype="" insertdate="" username="" />
<Service service_id="6" serviceitem_id="6" serviceitem_name="Lobster Shack" serviceitem_imgurl=""
serviceitem_description="Lobster Shack, the informal speciality restaurant on the beach front, serves the choicest seafood grills.
Open from October to April." serviceitem_availability=" Timings: 1930-2300 hrs." serviceitem_servicetype="" insertdate="" username="" />
</HSOutput>
Create another class ReadService.class
package com.example.readingservice;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import android.util.Log;
import android.widget.Toast;
public class ReadServices {
Document dest = null;
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser;
WebService webService=new WebService();
String values;
List<ServiceBean> serviceList;
/*
this is the guide list values reffering the Werservice class and listing out all the values
*/
/********************guide list start************************/
public List<Guide> getGuide() {
List<Guide> guideList = new ArrayList<Guide>();
SoapPrimitive soapObject=webService.getGuide(12);
values=soapObject.toString();
if(soapObject !=null){
SoapPrimitive soapObject1=webService.getGuide(12);
String src=soapObject1.toString();
try {
parser = dbFactory.newDocumentBuilder();
dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
NodeList locationNodeList2 = dest.getElementsByTagName("Guide");
if(locationNodeList2 != null && locationNodeList2.getLength() > 0){
for(int i=0;i<locationNodeList2.getLength();i++){
Node locationNode = locationNodeList2.item(i);
NamedNodeMap locNamedNodeMap = locationNode.getAttributes();
String guide_id=locNamedNodeMap.getNamedItem("guide_id").getNodeValue().toString();
String guide_name = locNamedNodeMap.getNamedItem("gudie_name").getNodeValue().toString();
//values=soapObject.toString();
Guide guide = new Guide();
guide.setId(guide_id);
guide.setName(guide_name);
guideList.add(guide);
}
}else{
}
}
return guideList;
}
/********************guide list end************************/
/***********************Service list start******************/
public List<ServiceBean> getService() {
serviceList = new ArrayList<ServiceBean>();
SoapPrimitive soapObject=webService.getService(7);
values=soapObject.toString();
if(soapObject !=null){
try {
parser = dbFactory.newDocumentBuilder();
dest = parser.parse(new ByteArrayInputStream(values.getBytes()));
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
NodeList locationNodeList2 = dest.getElementsByTagName("Service");
if(locationNodeList2 != null && locationNodeList2.getLength() > 0){
for(int i=0;i<locationNodeList2.getLength();i++){
Node locationNode = locationNodeList2.item(i);
NamedNodeMap locNamedNodeMap = locationNode.getAttributes();
String service_id=locNamedNodeMap.getNamedItem("service_id").getNodeValue().toString();
String service_name = locNamedNodeMap.getNamedItem("service_name").getNodeValue().toString();
Log.d("Service Id", service_id+"");
Log.d("Service Name", service_name+"");
values=soapObject.toString();
ServiceBean service = new ServiceBean();
service.setId(service_id);
service.setName(service_name);
serviceList.add(service);
}
Log.d("serviceList",""+serviceList.size());
return serviceList;
}else{
}
}
return serviceList;
}
/***********************Service list end******************/
/***********************ServiceItem list start******************/
public List<ServiceItemBean> getServiceItem() {
List<ServiceItemBean> serviceItemList=new ArrayList<ServiceItemBean>();
SoapPrimitive soapObject=webService.GetServiceItems(6);
values=soapObject.toString();
if(soapObject !=null){
try {
parser = dbFactory.newDocumentBuilder();
dest = parser.parse(new ByteArrayInputStream(values.getBytes()));
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
NodeList locationNodeList2 = dest.getElementsByTagName("Service");
if(locationNodeList2 != null && locationNodeList2.getLength() > 0){
for(int i=0;i<locationNodeList2.getLength();i++){
Node locationNode = locationNodeList2.item(i);
NamedNodeMap locNamedNodeMap = locationNode.getAttributes();
String serviceitem_id=locNamedNodeMap.getNamedItem("serviceitem_id").getNodeValue().toString();
String serviceitem_name=locNamedNodeMap.getNamedItem("serviceitem_name").getNodeValue().toString();
String serviceitem_availability = locNamedNodeMap.getNamedItem("serviceitem_availability").getNodeValue().toString();
String serviceitem_description = locNamedNodeMap.getNamedItem("serviceitem_description").getNodeValue().toString();
values=soapObject.toString();
ServiceItemBean serviceItem = new ServiceItemBean();
serviceItem.setId(Integer.parseInt(serviceitem_id));
serviceItem.setName(serviceitem_name);
serviceItem.setAvialbility(serviceitem_availability);
serviceItem.setDescription(serviceitem_description);
serviceItemList.add(serviceItem);
Log.d("Name :", ""+serviceitem_name);
Log.d("Avail :", ""+serviceitem_availability);
}
}else{
}
}
return serviceItemList;
}
/***********************ServiceItem list start******************/
}
here the method are reading the service which are all in xml string which is converted as invitial variable and paking as list
this can be checked as main activity
package com.example.readingservice;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
WebService webService=new WebService();
TextView tv;
String values;
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
// readServices();
ReadServices readServices=new ReadServices();
//readServices.getGuide();
// Log.d("**my Gude*", ""+readServices.getGuide().size());
//Log.d("**my Service*", ""+readServices.getService().size());
Log.d("My Service Itesm",""+readServices.getServiceItem().size());
//retriving the bean value
List<Guide> guideList=new ArrayList<Guide>();
guideList=readServices.getGuide();
Iterator<Guide> iterator=guideList.iterator();
while (iterator.hasNext()) {
Guide guide=iterator.next();
String name=guide.getName();
Log.d("my bean Value:", ""+name);
}
}