sandra abo

sandra abo

  • NA
  • 6
  • 925

Selecting Nodes in xmldocument

Nov 5 2016 4:05 PM
I am trying to call webservice and when hit search button to return value, the page throw error. I'm trying to parse data from calling API using xpath; 
Code:
  1. protected string getattributevalue(string id, XmlDocument doc)  
  2.         {  
  3.             // Load the document and set the root element.  
  4.             XmlNode root = doc.DocumentElement;  
  5.             
  6.             // Add the namespace.  
  7.             XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);  
  8.             nsmgr.AddNamespace("go""http://b.myserver.com/student/sign.xsd");  
  9.             String result;  
  10.   
  11.             // Select and display the first node in which the author's   
  12.             try  
  13.             {  
  14.             XmlNodeList nodelist = root.SelectNodes("//signup", nsmgr);  
  15.   
  16.            // Console.WriteLine(node.InnerXml);  
  17.             result = nodelist.Count.ToString();  
  18.             }  
  19.             catch (XPathException  ex)  
  20.             {  
  21.                 Console.Write(ex.ToString());  
  22.                 result = "Error: " + ex.ToString();  
  23.             }  
  24.             catch (NullReferenceException ex)  
  25.             {  
  26.                 Console.Write(ex.ToString());  
  27.                 result = "Error: " + ex.ToString();  
  28.             }  
  29.   
  30.             return result;  
  31.         }  
Error: System.NullReferenceException: Object reference not set to an instance of an object. at WebReg._Default.getattributevalue(String id, XmlDocument doc) in Default.aspx.cs:line 55  XmlNodeList nodelist = root.SelectNodes("//signup", nsmgr);
 

Answers (2)