Daniel Golan

Daniel Golan

  • NA
  • 45
  • 47.2k

Read xml error

Dec 19 2010 6:40 AM

Hello, working on a code to read xml, got a hint that i cant use xdocument since not valid characters in the xml.
The purpose of the code is to use the value from he cmblist to find a specifific node and print it in a txt box. Would be very happy for any help :)
The xml :
http://www.yr.no/sted/Norge/Akershus/Nesodden/Fjellstrand/varsel.xml
 
The code

XDocument xmlDoc = XDocument.Load("C:/Users/Daxal/documents/visual studio 2010/Projects/Yr/Yr/fjellstrand.xml");
 
var games = from game in xmlDoc.Descendants("weatherdata")
where game.Element("forecast").Element("text").Element("location").Element("time").Attribute("from").Value == cmb_sted.SelectedItem.ToString()
select new
{
Title = game.Element("title").Value,
Body = game.Element(
"body").Value,
};
 
txt_result.Text =
"";
foreach (var game in games)
{
//write values in txt box
txt_result.Text = txt_result.Text + "Title : " + game.Title + "\n";
txt_result.Text = txt_result.Text +
"Body : " + game.Body + "\n\n";
}
if (txt_result.Text == "")
txt_result.Text =
"No Results.";

Answers (6)