2010-03-15 36 views
-1

如何從cdata xmlnode獲取圖像源?從cdata xmlnode獲取圖像源

使用XMLNode:

<description>&lt;a href=&quot;http://www.site.com/id/?id=41564&quot;&gt;&lt;img src=&quot;http://www.site.com//news/images/2010/03_march/imagestock/thumb/22.jpg&quot; align=&quot;left&quot; /&gt;&lt;/a&gt; more text comes here </description> 

我試圖從描述節點獲得http://www.site.com//news/images/2010/03_march/imagestock/thumb/22.jpg了..

+2

是什麼「那」?你有什麼嘗試? – CommonsWare 2010-03-15 13:02:19

+0

我試圖獲得並打印src atrr值,然後發佈我的解決方案。 – ZoharAdar 2012-03-13 13:36:20

回答

1

OK,這是對我工作..

static String getImageFromFeed(String _HtmlString) { 

    Pattern p=null; 
    Matcher m= null; 
    String sUrl =""; 



    try { 

     p= Pattern.compile("src='(.*?)'"); 
     m= p.matcher(_HtmlString); 

    } catch (Exception e) { 
     sUrl = e.toString(); 
    } 

    if (m.find()) 
     { 
      sUrl=m.group(1); 

     } 

    return sUrl; 
}