0

I am trying to use Xml.Linq to read from an Xml I previously created by Xml.Linq. This is how XML looks like:

 <ItemsCollection>
  <Item>
    <ItemName>Computer</ItemName>
    <ItemDescription>Computer's description</ItemDescription>
    <ItemCategory>Electronics</ItemCategory>
    <ItemPrice>2499.99</ItemPrice>
  </Item>
</ItemsCollection>

Code responsible for parsing those elements into Item class objects is this:

 var res = from myItem in xdoc.Root.Elements("Item")
                      select new Item((string)myItem.Element("ItemName"), (string)myItem.Element("ItemDescription"),
                      (Category)Enum.Parse(typeof(Category), (string)myItem.Element("ItemCategory")), (double)myItem.Element("Price"));

When being executed, linq expression throws NullReferenceException.

wis.niowy
  • 87
  • 1
  • 12

0 Answers0