I load xml by Xdocument:
XDocument document = new XDocument();
document = XDocument.Load(filepath);
var list = document.Element("Items").Elements("Item").Select(Items.FromXElement).ToList();
If Xml file did not contain element “Item” or “Items” programm occurs a NullReference Exception.
How i can check my xml file on the content of elements, before this exception?
There are several ways to do this:
Option 1: XPath
Option 2: Helper method
Option 3: Validate your XML document against a schema