anupam_luv
New Member
Given the code:\[code\] var doc = new XmlDocument(); doc.LoadXml(@"<a> <b>test <c>test2</c> </b> </a>"); var node = doc.SelectNodes("/a/b")[0];\[/code\]I want to then extract the 'text' value of \[code\]node b\[/code\] - in this case "test", without retrieving all text elements from all child nodes (as .\[code\]innerText\[/code\] does)I find myself resorting to this code\[code\] var elementText = node.ChildNodes.Cast<XmlNode>().First(a => a.NodeType == XmlNodeType.Text).Value;\[/code\]As unfortunately \[code\]node.Value\[/code\] does something else in this caseis there a neater/inbuilt way without resorting to linq casting? that doesnt involve me doing something like;\[code\]foreach (var childNode in node.ChildNodes) if (childNode.NodeType==XmlNodeType.Text) ...\[/code\]