I am an android developer. I'm calling web service for one functionality and getting following code as output, when the web service is called.
<string xmlns="http://tempuri.org/">
<Response>
<Response_Code>0</Response_Code>
<Response_Description></Response_Description>
<Description></Description>
</Response>
</string>
In between the Description tag i get html code.
I want to display this on android app.
Can anybody tell me, how i can do this?
Thanks
use the following code as taken from http://developer.android.com/reference/android/webkit/WebView.html
and use a webview to display the data as:
String summary =<WHATEVER IS IN YOUR DESCRIPTION TAG> ;
webview.loadData(summary, "text/html", "utf-8");
You could also use the Html class.
someTextView.setText(Html.fromHtml(descriptionText));
Related
Hi I would like to send notifications with title and description. Except that the discription form is in html. there is a way to display it using:
Html.fromHtml () or same else
not like this
I am using Firebase to send notifications and in the app i use WebView like this
WebView .loadDataWithBaseURL("", "write html code here", "text/html", "UTF-8", "");
I hope it solve your problem. let me know if u need more help!
I would like to understand this problem i have been having.
Im parsing an html source page and displaying the content i want in a list view in android.
I parse the page using this command.
doc = Jsoup.connect(myURL).get();
Symbols such as é or “ ” show up as �.
I understand they are not being recognized by the encoding mechanism but is it because of jsoup or android?
Android default encoding im using is Utf-8 should it not support that?
If it should not how and what should i change it to?
Thank you for you help.
é in ISO-8859-1 (extend ASCII) is the value 233 but in UTF-8 it is the value 195 folowed by 169.
You need to know in what encoding the caracters are saved in because only the values are saved and then interpreted.
Thank you guys for the help.
making the jsoup call like this :
Document document = Jsoup.parse(new URL(url).openStream(), "ISO-8859-1", url);
was the way to go i then had to find out the real encoding of the webpage in chrome you can find it in 'more tools' and in my case it was
windowns-1252. One line of code solved the problem:
doc = Jsoup.parse(new URL(url).openStream(), "windows-1252", url);
I'm facing some problems with Jsoup. I'm trying to retrieve an xml file from Open Movie Database using their API in my beta Android app.
Their API documentation says if the return type will be an xml just put an "r=" and the return file type.
I've tested with some requests. Below one of them:
Jsoup.connect(http://www.omdbapi.com/?i=tt1285016&r=xml).get();
Testing on a browser works fine. But on android no. Any exception is thrown. If I don't insert the return file type, it returns a JSON. In this case I receive the data.
To make sure if the problem is with xml file. I've teste with MusicBrainz API. By default it returns XML. For my surprise works fine.
What is the problem? The return type of open movie database of Jsoup?
Jsoup's primary focus is in dealing with HTML, and making sure that the returned document is well formed HTML. So by default it will always treat the input as HTML and will normalise the document. That's why you're getting a DOM like <html><head></head>...<xml>...</html>.
If you know the input you're giving it is actually XML, you can configure Jsoup to parse in XML mode. In that case it will not normalise to a HTML DOM, and it will not enforce any HTML spec rules.
As an example:
String url = "http://www.omdbapi.com/?i=tt1285016&r=xml";
Document doc = Jsoup.connect(url)
.parser(Parser.xmlParser())
.get();
System.out.println(doc);
Compare that output with and without the Parser.xmlParser() configuration:
In XML mode:
<?xml version="1.0" encoding="UTF-8"?>
<root response="True">
<movie title="The Social Network" year="2010" {snip} />
</root>
In HTML mode:
<!--?xml version="1.0" encoding="UTF-8"?-->
<html>
<head></head>
<body>
<root response="True">
<movie title="The Social Network" {snip} />
</root>
</body>
</html>
Found the problem. The values were always there. I don't know why but the return type is an html file with xml tags included. Printing values on Logcat it returns html tags html, head, body and only after this the XML.
when i try to get the html source code from webview i use this example for my solution:
Extracting HTML from a WebView
now i want to parse a page which has no html content. the page displays only a text extracted from xml source.
does anybody have an idea how to get the content (or xml source code) from webview?
best regards
EXAMPLE: XML
< ID >test< /ID > <BR>
< Status >0< /Status >
Is shown as: test0 in webview
I want get the "test0" and put it to string
Option #1: Use the same approach as is shown in the linked-to blog post. Devise some JavaScript that grabs the data out of your Web page and call that JavaScript via loadUrl(), routing the results to some JavaScript interface you injected into the WebView via addJavascriptInterface().
Option #2: Don't use WebView at all, and use HttpURLConnection or HttpClient to fetch the XML source.
I used the tutorial listed here to parse my XML:
http://android-er.blogspot.com/2010/05/simple-rss-reader-iii-show-details-once.html
The problem I am having is when I try to read in the XML description tag all I get is this:
The "<" symbol is where the description should go. This is the feed I am reading: http://www.calvaryccm.com/rss/devos.ashx
Please help me solve my issue in getting the real text into the description. Thank you!
I just created an android project in eclipse using the code I downloaded from the site you listed above. I only made one modification to the original sources. I changed line 33 in AndroidRssReader.java to read:
URL rssUrl = new URL("http://www.calvaryccm.com/rss/devos.ashx");
The feed loads and parses fine.
The parsing error is the result of changes you made to the original sources.
If the data is html encoded, you can use one of the following methods -- or if it is unencoded, you can surround the content in CDATA tags.
Spanned spannedContent = Html.fromHtml(htmlString);
textView.setText(spannedContent, BufferType.SPANNABLE);
or
WebView webview = (WebView) findViewById(R.id.aWebView);
String htmlString = "<html><body>Some html</body></html>";
webview.loadData(htmlString, "text/html", "utf-8");
I found out that I need to wrap my RSS tags in CDATA Tags as shown here:
Writing input for .NET web services