Learn Linq to XML With C# - Part 3: How to Access a Single Element in XML File

preview_player
Показать описание
Subscribe for more lessons

How to access single elements in an Xml file using Linq to Xml with C#
Рекомендации по теме
Комментарии
Автор

Hi Kindson
And thank's for these tutorials.
However I'm having an issue when trying to access specific elements.

Up to this point tutorial 1 and 2 works exactly the same form me as you.

But from tutorial 3 I can't get the same result you get. Whatever tag I try to access.
I get a nullreference exception on this line inside the foreach loop
where I try to access the value of the element.

foreach(var book in books)
{
string = <= // here
Console.WriteLine( tagname);

}


What have I done wrong, it's doing my head in?

I don't have the exact same xml file as you but that shouldn't matter, the procedure should be the same regardless right?

eddieandersson