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)
- {
- // Load the document and set the root element.
- XmlNode root = doc.DocumentElement;
- // Add the namespace.
- XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
- nsmgr.AddNamespace("go", "http://b.myserver.com/student/sign.xsd");
- String result;
- // Select and display the first node in which the author's
- try
- {
- XmlNodeList nodelist = root.SelectNodes("//signup", nsmgr);
- // Console.WriteLine(node.InnerXml);
- 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);
Manas MohapatraPosted Nov 6, 2016, 1:33 AM
Bikesh SrivastavaPosted Nov 5, 2016, 11:04 PM