pletcherfpd
New Member
I know there are many questions on this very topic but none of the examples I've tried have worked for me.I have an existing XML document that is constructed like so:\[code\]<root> <ElementA> <element1>sometext</element1> <element2>sometext</element2> <element3>sometext</element3> </ElementA> <ElementA> <element1>sometext</element1> <element2>sometext</element2> <element3>sometext</element3> </ElementA> <ElementB> <element1>sometext</element1> <element2>sometext</element2> <element3>sometext</element3> <element4>sometext</element4> <element5>sometext</element5> </ElementB> <ElementB> <element1>sometext</element1> <element2>sometext</element2> <element3>sometext</element3> <element4>sometext</element4> <element5>sometext</element5> </ElementB> <ElementC> <element1>sometext</element1> <element2>sometext</element3> </ElementC> <ElementC> <element1>sometext</element1> <element2>sometext</element2> </ElementC></root>\[/code\]I need to find all the ElementA, B, and Cs and create a new object of type objA, etc. whose properties correspond to the respective element's child elements. Below is example code that I've tried.\[code\]var doc = XElement.Load(filename);var data = http://stackoverflow.com/questions/15599579/from ele in doc.Elements() where ele.Name.LocalName.Equals("ElementA") select new objA { name = ele.Element("element1").Value address = ele.Element("element2").Value };\[/code\]But this throws a null exception error when I try iterating through "data" collection. What am I not understanding?