Skip to content Skip to sidebar Skip to footer

Android - Eclipse How To Get Web View Text Content In String

i tried different codes but fail very time. i got webview containing text i would like to take all text into string. here i can getting webview browser = (WebView) findVie

Solution 1:

To get text content from HTML, use XmlPullParser.

Here are references:

Google developer doc

Tutorial on XML parsing

private String readText(String htmlStr)throws IOException, XmlPullParserException {

             StringtoReturn="";
             XmlPullParserFactoryfactory= XmlPullParserFactory.newInstance();
             factory.setNamespaceAware(true);
             XmlPullParserxpp= factory.newPullParser();

             xpp.setInput(newStringReader ("htmlStr"));
             inteventType= xpp.getEventType();
             while (eventType != XmlPullParser.END_DOCUMENT) {
              if(eventType == XmlPullParser.TEXT) {
                  toReturn = "Text "+ xpp.getText());
              }
              eventType = xpp.next();
             }
            return toReturn;
}

Post a Comment for "Android - Eclipse How To Get Web View Text Content In String"