Parse XML to ordered list
I'm using the following code to parse my XML document into an unordered list. When the code complete's, I get "undefined" in both my hyperlink and text field. Below is an example of my XML and my HTML.
Here is my current HTML page
- <html>
- <head>
- <title>Test News Feed</title>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
- <script type="text/javascript">
- $(document).ready(function()
- {
- $.ajax({
- type: "GET",
- url: "10.0.8.10/feeds/rss/news-feed-2/",
- dataType: "xml",
- success: function(xml) { parseXml(xml); }
- });
- });
- function parseXml(xml)
- {
- $(xml).find("item").each(function()
- {
- $("#news").append("<li><a href='" + $(this).attr("link") + "'>" + $(this).attr("title") + "</a></li>");
- });
- }
- </script>
- </head>
- <body>
- <div>
- <ul id="news"></ul>
- </div>
- </body>
- </html>
Also, how would I modify the function parseXml to only show the 5 most recent items.