Using selectNodes() and selectSingleNode() with XPath Expressions.
Listing 1. Internet Explorer 5+ provides robust DOM APIs that can be used to parse XML data. This example shows how the selectNodes() and selectSingleNode() methods can be used with XPath expressions to parse an RSS feed and output the results to a page. function GetRss() { XmlForAsp.ScriptMethodService.GetRssFeed( "http://weblogs.asp.net/dwahlin/rss.aspx",OnWSRequestComplete); } function OnWSRequestComplete(result) { if (document.all) { //Locate all <item> tags in RSS feed data var items = result.selectNodes("//item"); for (var i=0;i<items.length;i++) { //Write out title and link values from RSS feed var title = items[i].selectSingleNode("title").text; var href = items[i].selectSingleNode("link").text; $get("divOutput").innerHTML += "<a href='" + href + "'>" + title + "</a><br />"; } } else { $get("divOutput").innerHTML = "RSS only available in IE5+"; } } |