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:
- protected string getattributevalue(string id, XmlDocument doc)
- {
-
- XmlNode root = doc.DocumentElement;
-
-
- XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
- nsmgr.AddNamespace("go", "http://b.myserver.com/student/sign.xsd");
- String result;
-
-
- try
- {
- XmlNodeList nodelist = root.SelectNodes("//signup", nsmgr);
-
-
- result = nodelist.Count.ToString();
- }
- catch (XPathException ex)
- {
- Console.Write(ex.ToString());
- result = "Error: " + ex.ToString();
- }
- catch (NullReferenceException ex)
- {
- Console.Write(ex.ToString());
- result = "Error: " + ex.ToString();
- }
-
- return result;
- }
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);