i am parsing xml thru jQuery fine like this
xmlCode:$(document).ready(function(){ $.ajax({ type: "GET", url: "jquery_xml.xml", dataType: "xml", success: parseXml, error: err }); }); function err(xhr, reason, ex) { $('#output').append(reason); } function parseXml(xml){ $(xml).find("Tutorial").each(function(){ $("#output_2").append($(this).find("Categories").text() + "<br />"); }); }
but this returns ALL the nodes under Categories.Code:<?xml version="1.0" encoding="iso-8859-1"?> <RecentTutorials> <Tutorial author="The Reddest"> <Title>Silverlight and the Netflix API</Title> <Categories> <Category>Tutorials</Category> <Category>Silverlight 2.0</Category> <Category>Silverlight</Category> <Category>C#</Category> <Category>XAML</Category> </Categories> <Date>1/13/2009</Date> </Tutorial> <Tutorial author="The Hairiest"> <Title>Cake PHP 4 - Saving and Validating Data</Title> <Categories> <Category>Tutorials</Category> <Category>CakePHP</Category> <Category>PHP</Category> </Categories> <Date>1/12/2009</Date> </Tutorial> <Tutorial author="The Tallest"> <Title>Silverlight 2 - Using initParams</Title> <Categories> <Category>Tutorials</Category> <Category>Silverlight 2.0</Category> <Category>Silverlight</Category> <Category>C#</Category> <Category>HTML</Category> </Categories> <Date>1/6/2009</Date> </Tutorial> <Tutorial author="The Fattest"> <Title>Controlling iTunes with AutoHotkey</Title> <Categories> <Category>Tutorials</Category> <Category>AutoHotkey</Category> </Categories> <Date>12/12/2008</Date> </Tutorial> </RecentTutorials>
How can i target a particular node under Categories such as Category[1]
so that i output the second entry under this node? i have attached my files
thanks in advance



Reply With Quote

Bookmarks