0

我正在解析一个 xml 提要,并且我有以下标签

<content:encoded>
<![CDATA[
<p><a href="http://www.highlandradio.com/wp-content/uploads/2013/07/An-Grianan-Hotel.jpg"><img class="aligncenter size-full wp-image-54286" alt="An Grianan Hotel" src="http://www.highlandradio.com/wp-content/uploads/2013/07/An-Grianan-Hotel.jpg" width="488" height="244" /></a></p> <p>Gardai are appealing for information about last an armed robbery at An Grianan Hotel in Burt in the earkly hours of this morning..</p> <p>Three men entered the premises at quarter to three, at least one was armed with a shotgun. They escaped with a sum of money.</p> <p>Local Superintendent Andy Archbold is leading the investigation, and has been outlining what happened&#8230;&#8230;&#8230;&#8230;..</p> <p><strong> </strong></p>
]]>
</content:encoded>

我需要能够从中获取图像。我想知道最好的方法是什么?我可以搜索正则表达式吗?另外关于 … 等有没有办法轻松转换这些?所有帮助表示赞赏。下面是我当前获取提要并循环通过它的代码,我的目标是将我的数据数组的 leftImage 元素设置为内容编码标签内的图像。

var url="http://www.highlandradio.com/feed/"; 
//rss feed url
var xhr = Titanium.Network.createHTTPClient();

xhr.onload = function() {
    // Data is returned from the blog, start parsing
    var doc = this.responseXML.documentElement;

    // begin looping through blog posts
    var items = doc.getElementsByTagName("item");
    console.log(items);
    for (var i=0;i<items.length;i++) {
        data.push({                
            title: "'"+items.item(i).getElementsByTagName("title").item(0).text+"'",
            leftImage:'NewsStory.png',
            dataToPass: "'"+items.item(i).getElementsByTagName("description").item(0).text+"'",    
            className: "TableRow", 
            hasChild: true, 
            jsTest: true,
            js:"external.js"
        });
}
};

.

4

1 回答 1

0

正则表达式是模式搜索的最佳方式。像这样的正则表达式也许可以帮助你:

<img\s.*?src=\"(.*?)\".*?/>

此正则表达式提取 scr 属性值,在您的示例中: http ://www.highlandradio.com/wp-content/uploads/2013/07/An-Grianan-Hotel.jpg

于 2013-07-12T13:37:49.930 回答