What is null when importing the XML?

neotesterz

New Member
I'm trying to import data from an xml file and sort them in order, but when i run it, i get "Object reference not set to an instance of an object." here is a snippet of the code im using.\[code\]XElement data = http://stackoverflow.com/questions/10515960/XElement.Load("blockData.xml");var sortedElements = from c in data.Element("BLOCKS").Elements("BLOCK")orderby (string)c.Element("X") descending, (string)c.Element("Y") descending, (string)c.Element("Z") descending select new { name1 = (string)c.Element("NAME"), X1 = (string)c.Element("X"), Y1 = (string)c.Element("Y"), Z1 = (string)c.Element("Z") }; foreach (var r in sortedElements) Console.WriteLine("X:{0} Y:{1} Z:{2} Name:{3}", r.X1, r.Y1, r.Z1, r.name1);\[/code\]And a sample of what is contained in the XML file\[code\]<BLOCKS> <BLOCK> <NAME>B1</NAME> <X>0</X> <Y>0</Y> <Z>0</Z> </BLOCK></BLOCKS>\[/code\]
 
Back
Top