Hi I'm new to Eclipse and coding in general, and have been attempting to make a simple app to improve my skills. I've run into a bit of a snag trying to reproduce a table from a webpage in my app. I've spent hours consulting forums on how to do so but it just doesn't seem to work. I am attempting to parse the page using JSoup. I have downloaded and imported Jsoup. Here is the java I have at the moment:
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Standingspage extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_standingspage);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.standingspage, menu);
return true;
}
public static void main(String[] args) throws Exception {
Document doc = Jsoup.connect("http://pcihl.ca/Statistics/RegularSeasonStandings").get();
for (Element table : doc.select("table")) {
for (Element row : table.select("tr")) {
Elements tds = row.select("td");
System.out.println(tds.get(0).text());
}
}
}
}
I don't have anything special in the related xml code besides some layout info. When I run the app on the virtual device I get nothing but a blank page.
Any help or advice would be greatly appreciated and please remember that i'm new at this.
Thanks,
Kindly use ksoap2-android library..
example : -
private static final String NAMESPACE = YOUR_URL_IN_STRING;
private static final String HEADER = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>";
private static final int SOAP_VERSION = SoapEnvelope.VER11;
in method
long startTime=System.currentTimeMillis();
String METHOD_NAME = "CheckDeviceRegistration";
String SOAP_ACTION = NAMESPACE + METHOD_NAME;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("deviceCode", deviceCode);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SOAP_VERSION); // put all required data into a soap envelope
envelope.dotNet = true;
// envelope.addMapping(NAMESPACE, "GetApplicationConfigurations", GetApplicationConfigurations.class);
// envelope.headerOut = security; // this is an Element[] created before
// envelope.encodingStyle = SoapEnvelope.ENC;
envelope.setAddAdornments(false);
envelope.implicitTypes = false;
envelope.setOutputSoapObject(request); // prepare request
HttpTransportSE httpTransport = new HttpTransportSE(URL, timeOut);
httpTransport.debug = DEBUG; // this is optional, use it if you don't want to use a packet sniffer to check what the sent
// message was (httpTransport.requestDump)
httpTransport.setXmlVersionTag(HEADER);
try {
httpTransport.call(SOAP_ACTION, envelope);
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} // send request
Log.d("RAM RAM3", "XML: " + httpTransport.requestDump);
SoapObject result = null;
String returnString = "";
try {
envelope.getResponse();
result = (SoapObject) envelope.bodyIn;
returnString = result.getProperty(0).toString();
} catch (Exception e) {
e.printStackTrace();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.