I am trying to access element at first level in given xml. I am using below code to access it but it gives me nested one as it come first.
var xml = "<grading>" +
"<leap>" +
"<controlId>1</controlId>" +
"</leap>" +
"<controlId>2</controlId>" +
"</grading>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
var node = doc.DocumentElement.SelectSingleNode("//controlId").InnerText;
It is giving me value 1 while i am trying to access value 2 which is inside root node. Do we have any by which we can access it.
/)... it would help if you'd provide code that demonstrates the actual problem. I'd second the recommendations to use LINQ to XML though.//that means "find the first descendant". If you just useSelectSingleNode("controlId")it will work, although I'd definitely recommend using LINQ to XML instead.