Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
2
Answers
Selecting Nodes in xmldocument
sandra abo
8y
262
1
Reply
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);
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
How to pass user credentials in SOAP header.
How WCF hosted on IIS?