我想从此链接中提取XML
http://212.12.182.204:8090/NewsService.svc/LatestNews
使用JavaScipt,我已经完成并搜索了大量代码,但我认为错误存在于链接或提取本身,我不确定,因为我是新手。
谢谢
编辑部分: 我在谷歌代码游乐场使用的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google AJAX Search API Sample</title>
<script src="//www.google.com/jsapi?key=AIzaSyA5m1Nc8ws2BbmPRwKu5gFradvD_hgq6G0" type="text/javascript"></script>
<script type="text/javascript">
/*
* How to receive results in XML.
*/
google.load("feeds", "1");
// Our callback function, for when a feed is loaded.
function feedLoaded(result) {
if (!result.error) {
// Get and clear our content div.
var content = document.getElementById('content');
content.innerHTML = '';
// Get all items returned.
var items = result.xmlDocument.getElementsByTagName('News');
// Loop through our items
for (var i = 0; i < items.length; i++) {
var item = items[i];
// Get the title from the element. firstChild is the text node containing
// the title, and nodeValue returns the value of it.
var title = item.getElementsByTagName('Title')[0].firstChild.nodeValue;
content.appendChild(document.createTextNode(title)); // Append the title to the page
content.appendChild(document.createElement('br')); // Add a new line
}
}
else
{
alert(result.error.code);
}
}
function OnLoad() {
// Create a feed instance that will grab Digg's feed.
var feed = new google.feeds.Feed("http://212.12.182.204:8090/NewsService.svc/LatestNews");
// Request the results in XML
feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
// Calling load sends the request off. It requires a callback function.
feed.load(feedLoaded);
}
google.setOnLoadCallback(OnLoad);
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id="content">Loading...</div>
</body>
</html>