Here i would like to retrieve the value of the node <test1>, for this i have tried the following but unable to solve the error in the first few lines of code.
var xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath(@"\Test.xml"));
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmldoc.NameTable);
nsmgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
nsmgr.AddNamespace("csc", "https://Somepath");
var deviceType = xmldoc.DocumentElement.SelectNodes("/soapenv:Body/", nsmgr);
I have got the following error from the lastline of code,
Here i would like to retrieve the value of the node <test1>, for this i have tried the following but unable to solve the error in the first few lines of code.
I have got the following error from the lastline of code,
Expression must evaluate to a node-set.
You need to map the node accordingly and ensure that you provided till the parent node to get value properly.
You can try with the below code
var xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath(@"\Test.xml"));
//Create NameSpaceManager
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmldoc.NameTable);
//Add the namespace of xml here
nsmgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
nsmgr.AddNamespace("csc", "https://Somepath");
//Get the test1 number node
XmlNode test1node = xmldoc.SelectSingleNode("soapenv:Envelope/soapenv:Body/csc:getMenuEligibleOptionsRequest/test1", nsmgr);
//Get the text1
string test1vale = test1node.InnerText;
Member
34 Points
73 Posts
Unable to get the XML node value
Oct 26, 2015 11:03 AM|nagarajasia|LINK
Hi Members,
I am trying to retrieve the value of certain node from XML file, in my asp.net Application.
Since this is my first ever code using XML, i couldn't successfully retrieve the my desired node value. Could any one please help me on that,
My XML:
Here i would like to retrieve the value of the node <test1>, for this i have tried the following but unable to solve the error in the first few lines of code.
I have got the following error from the lastline of code,
Expression must evaluate to a node-set.
Nagaraj.S
All-Star
50831 Points
9895 Posts
Re: Unable to get the XML node value
Oct 26, 2015 11:26 AM|A2H|LINK
You need to map the node accordingly and ensure that you provided till the parent node to get value properly.
You can try with the below code
Aje
My Blog | Dotnet Funda
Member
34 Points
73 Posts
Re: Unable to get the XML node value
Oct 26, 2015 01:00 PM|nagarajasia|LINK
Appreciate your immediate reply. Thanks a lot
Nagaraj.S