0

I want to extract the XML from this link

http://212.12.182.204:8090/NewsService.svc/LatestNews

with JavaScipt, I've done and searched for loads of codes but I think the error is in the link or feed itself, I'm not sure as I'm new to this.

Thank you

EDITED PART: the code I used from google code playground:

<!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>
Joseph Khella
  • 695
  • 1
  • 9
  • 26
  • @Teemu I tried loads of codes, and they extract the data in any link, but this link, although it can be opened in the browser – Joseph Khella Jul 17 '14 at 09:58
  • Possible Duplicate [Extracting XML data using javascript](http://stackoverflow.com/questions/18933217/extracting-xml-data-using-javascript) – Izzy Jul 17 '14 at 09:59
  • @Izzy nope, It would be a duplicate if I didn't search and my answer is out there, But I already searched and didn't find an answer for my problem which I believe it may be in the link itself and I need an answer from someone experienced – Joseph Khella Jul 17 '14 at 10:01
  • this question has been asked a few times already. try these links: http://stackoverflow.com/questions/8237923/parsing-xml-rss-from-url-using-java-script .. http://stackoverflow.com/questions/13137467/get-xml-data-from-url-using-js-code – sunbabaphu Jul 17 '14 at 10:06
  • @sunbabaphu Nope, I believe there's something wrong with the URL itself, even google reader can't extract the data in it – Joseph Khella Jul 17 '14 at 10:18
  • the url is fine! to check: goto http://xmlgrid.net/ ; click `by Url`; paste your link; submit ... it displays your `Xml` in `TextView` – sunbabaphu Jul 17 '14 at 10:25
  • also, do post you `JS` code here – sunbabaphu Jul 17 '14 at 10:27
  • @sunbabaphu I can see, well can you give me a way to read it? I really failed in reading it, and thanks for proving that the data is fine. – Joseph Khella Jul 17 '14 at 10:29
  • @sunbabaphu I updated the description with the code – Joseph Khella Jul 17 '14 at 10:38
  • how about this link: http://stackoverflow.com/a/11244974/2857402 – sunbabaphu Jul 17 '14 at 10:55
  • @sunbabaphu working with any link, but not working with the link I need =/ – Joseph Khella Jul 17 '14 at 11:19
  • @sunbabaphu it tells me that "the port specified in the feed url is not supported" – Joseph Khella Jul 17 '14 at 11:31

0 Answers0