xml - Null Reference Exception in C# application -


this question has answer here:

following code throws

system.nullreferenceexception

 private void btnload_click(object sender, eventargs e)     {         openfiledialog ofd = new openfiledialog();         ofd.title = "xml-datei auswählen";         ofd.filter = "xml-dateien|*.xml";         ofd.initialdirectory = @"c:\";          if (ofd.showdialog() == dialogresult.ok)         {             xmldocument xdoc = new xmldocument();             xdoc.load(ofd.filename);              foreach (xmlnode node in xdoc.selectnodes("people/person"))             {                 int age = int.parse(node.attributes["age"].value);                 messagebox.show((age + 1).tostring());             }         }      } 

the error occurs in line

age = int.parse(node.attributes["age"].value); 

in locals window can see, reference attribut "age" remains null.

the .xml-file structured that:

<people>   <person>    <name>testperon</name>    <age>29</age>    <email>me@testmail.com</email>    </person>  </people>

thank you!

there no attribute name, element.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -