Retrieving Data from a remote XML File and add to datagrid

greysilverfang

New Member
I have an XML file that I have no write access to it .. I retrieve it online.I have the code below, which works fine, but I can't move forward ..\[code\]using System.Data;using System.Xml.Linq;try{ XDocument XMLFile = XDocument.Load(@"http://Domain/path/to/file.xml"); MessageBox.Show("Remote File Loaded Successfully ..."); var items = XMLFile.Descendants("item"); int i = 0; foreach (var item in items) { i++; //var title = item.Descendants("title"); //MessageBox.Show(title.ToString()); } MessageBox.Show("Items Found: " + i);}catch(exception ex){ MessageBox.Show("Error: " + ex.Message.ToString()); MessageBox.Show("Error: " + ex.InnerException.ToString());}\[/code\]The problem I'm facing is in the \[code\]foreach\[/code\] loop. Every root element item has some child elements. I can't figure out how to retrieve those elements!!Also, I have a grid view, I want to add the result to it, how can I achieve that??Thank.EDITXML Sample:\[code\]<item> <title>Title</title> <link>http://domain/link</link> <description>Some Text</description> <pubDate>Wed, 05 Dec 2012 01:29:37 -0500</pubDate> <guid isPermaLink="false">Domain_text_INTEGER</guid> <category domain="http://domain/link">A</category> <category domain="http://domain/link">B</category> <category domain="http://domain/link">C</category> <category domain="http://domain/link">D</category> <category domain="http://domain/link">E</category> <coop:keyword>A</coop:keyword> <coop:keyword>B</coop:keyword> <coop:keyword>C</coop:keyword> <coop:keyword>D</coop:keyword> <coop:keyword>E</coop:keyword> <coop:keyword>Text</coop:keyword> <coop:keyword>Text</coop:keyword> <coop:keyword>Text</coop:keyword> <coop:keyword>Text</coop:keyword> <coop:keyword>Text</coop:keyword> <coop:keyword>Text</coop:keyword> <coop:keyword>Text</coop:keyword> <coop:keyword>Text</coop:keyword> <coop:keyword>Text</coop:keyword> <coop:keyword>Text</coop:keyword> <coop:keyword>text integer</coop:keyword> <coop:keyword>Text</coop:keyword></item>\[/code\]What I need from it:
  • Title
  • Link
  • Description
  • PubDate
  • Guid (INTEGER) <= I can get the integer from the string OR text integer
Thanks.
 
Back
Top