I m new in Android development and never been in JAVA before.
With online tutorials and stackoverflow help I managed to generate a list with XML,
Now I m making it work like if I clicked on list item, it will open other activity.
With php I managed to generate xml I want on request but now in android I want that single entry XML
<item name="something"><description>Item description</description></item>
like this. But I'm not sure how can I read this remote xml and store values as a string
String name = Name attribite value & same for description.
You should use a parser like as Pullparser, Saxparser or something what you need.
You can follow the following: Parsing example
Make one SOAP Web service and call it from Android application. Please find tutorial here
Regarding SOAP:- http://suda.co.uk/publications/MSc/brian.suda.thesis.pdf
And regarding how to use with Android:- http://androidtestexample.blogspot.in/2012/02/soap.html
Related
I am trying to build my new App and I need some data for it.
so I was wondering if I can get JSON data (or query link or any source file) of any site for now and for future.
I need to get data from this site:
https://study.ekb.eg/ - https://www.ekb.eg/
Note: https://www.ekb.eg/ is the main source data for https://study.ekb.eg/
Thanks
The site needs to be specifically programmed to return JSON data for you. Regular, normal sites are not like this. They generally just return HTML
So the site owner would need to set up an API for you to consume
I am trying to sort a Google Spreadsheet with the Java API but unfortunately it doesn't seem to work. The code I am using is really simple as shown in the API reference.
URL listFeedUrl = new URI(worksheet.getListFeedUrl().toString() + "?orderby=columnname").toURL();
However, this does not work. The feed returned is not sorted at all. Am I missing something? FYI the column I am trying to sort contains email addresses.
EDIT: I just realized that the problem only happens with the old version of Google Spreadsheet.
maybe this happens. The query is performed on the spreadsheet xml and xml tags are in lower case, for example the title of my column in my spreadseet is "Nombre" and the xml <gsx:nombre>is not working so instead of using [?orderby=Nombre], use [?orderby=nombre] with a lowercase "n"
The correct query for this is.
URL listFeedUrl = new URI(worksheet.getListFeedUrl().toString() + "?orderby=nombre").toURL();
Well I'm kinda new to android and I'm trying to get a value of a http answer. But I never worked with that XML stuff before.
Example of web service : http://freegeoip.net/xml/123.123.123.123
this is the result here
<Response>
<Ip>123.123.123.123</Ip>
<CountryCode>CN</CountryCode>
<CountryName>China</CountryName>
<RegionCode>22</RegionCode>
<RegionName>Beijing</RegionName>
<City>Beijing</City>
<ZipCode/>
<Latitude>39.9289</Latitude>
<Longitude>116.388</Longitude>
<MetroCode/>
</Response>
how to get the value of countrycode, regioncode etc...
You should use SAX API (Simple Api for XML) to parse the xml from the webservice and handle it with the DefalutHandler class.Here's the documentation of DefaultHandler class: http://developer.android.com/reference/org/xml/sax/helpers/DefaultHandler.html
and here's a nice tutorial from 0 which should help you: http://www.codeproject.com/Articles/334859/Parsing-XML-in-Android-with-SAX
I'm writing an android magazine reader for a campus publication I work for. We use wordpress to publish our website, and I want to leverage the wordpress REST API to pull stories (posts) directly from the website, without publishers having to take any additional steps to publish posts on the app after publishing them on the site. I'll do this by getting JSON objects representing posts and deserializing them into POJOs of the Story class (defined in the android application), around which views will then be built dynamically.
I've just discovered the Wordpress REST API and am really excited because I think that the implementation as described above is going to be pretty simple. Are there any obvious roadblocks that I'm missing that might complicate things?
I know that the API responds with a "content" parameter that is a string containing the HTML code for the post, with references to included images/media in the appropriate places. How can I get Android to load that html and display it properly in a WebViewer?
If you don't want to parse the html and separately load images and other resources, simply use
loadDataWithBaseURL like so:
WebView storyView = (WebView) findViewById( .... );
String htmlToDisplay = ....;
storyView.loadDataWithBaseURL( "http://storysite.com/', htmlToDisplay, mimeType, encoding, "" );
The baseURL will be prepended to all relative partial URIs found in the document, so that the WebView can take care of loading all other assets for you.
I'm relatively new to java and android, in my android application I need to get an XML file, transform it and show it to a user.
I know how to parse XML, but I don't want to parse it and generate views after. I'd like to transform it to an HTML and display in a WebView.
I'm trying to find something on the Internet but can't find anything.
How can I do it? Any ideas or links will be appreciated,
thanks
The usual tool to use for transforming XML to HTML is XSLT. Search SO for XSLT tutorial and you'll get some good results.
Here is another question showing how one developer used XSLT on Android.
You can also search for examples of the use of Transformer in Java, as in this helpful article:
// JAXP reads data using the Source interface
Source xmlSource = new StreamSource(xmlFile);
Source xsltSource = new StreamSource(xsltFile);
// the factory pattern supports different XSLT processors
TransformerFactory transFact =
TransformerFactory.newInstance();
Transformer trans = transFact.newTransformer(xsltSource);
trans.transform(xmlSource, new StreamResult(System.out));
Update:
For older versions of the Android java API:
This article shows how to use a SAX parser to parse the input XML, then use XmlSerializer to output XML. The latter could easily output whatever XHTML you want. Both are available since API level 1.
Unfortunately I don't see a way to do XPath in API level 3, but if your input XML isn't too complex you should be able to code your own transformations. I know you "don't want to parse it and generate view after", but if you mean you don't want to even use an XML parser that's provided by Android, then I don't know of any alternative.
Update 2:
I just learned about XOM, which supports a subset of XPath. This question shows someone using XOM on Android (to write XML) with API level 4. You could take advantage of the XPath features, as well as the serialization features. It requires a small external library, XOM's jar. I don't know if it's compatible with API level 3.
Please see the complete working example, created as a part of "AndStatus" application.
It uses XSLT to show localized (!) Application Change Log in a WebView of the HelpActivity.
The working example consists of these parts:
The small utility class without any dependencies (i.e. it may be easily reused) which has this function:
/**
Transform XML input files using supplied XSL stylesheet and show it in the WebView
#param activity Activity hosting the WebView
#param resView WebView in which the output should be shown
#param resXml XML file to transform. This file is localized! It should be put into "raw-" folder
#param resXsl XSL stylesheet. In the "raw" folder. May be single for all languages...
*/
public static void toWebView(Activity activity, int resView, int resXml, int resXsl) {
...
}
See full source code here: Xslt.java
The example of its usage: See HelpActivity.java
The XML file to be transformed: changes.xml
and the corresponding XSL stylesheet: changesxsl.xsl
Use XSLT, XSLT convert your XML in to HTML that we can display in Android Webview.
This question will help.