android java get html image tag from string

后端 未结 4 569
深忆病人
深忆病人 2020-12-10 07:33

Im trying to get HTML image tag url from the given string. There should be some regular expression to get it. But don\'t know how to do it. Can anyone help me on this.

4条回答
  •  粉色の甜心
    2020-12-10 07:51

    An XMLPullParser can do this pretty easily. Although, if it is a trivially small string, it may be overkill.

         XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
         XmlPullParser xpp = factory.newPullParser();
    
         xpp.setInput( new StringReader ( "I have string like this with 
    some HTMLtag with image tags in it. how can get it ?" ) ); int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if(eventType == XmlPullParser.START_TAG && "img".equals(xpp.getName()) { //found an image start tag, extract the attribute 'src' from here... } eventType = xpp.next(); }

提交回复
热议问题