how to read mulitiple elements from the same node
i want to read to nodes from xml now getting only linktext, want linkurl also.. can u pls help in this
lst = targetNode.AncestorsAndSelf().Elements("LinkText").Select(p => p.Value).ToList<string>();
<LeftMenu>
<linkid>1</linkid>
<linkurl>www.h1.com</linkid>
<NavLinks>
<linkid>2</linkid>
<linkurl>www.h2.com</Linkurl>
<nav2>
<linkid>3</linkid>
<linkurl>www.h3.com</Linkurl>
<nav2>
开发者_StackOverflow社区 </NavLinks>
</leftmenu>
You can just grab the LinkUrl elements and add them to the same list:
lst = targetNode.AncestorsAndSelf().Elements("LinkText").Select(p => p.Value).ToList();
lst.AddRange(targetNode.AncestorsAndSelf().Elements("LinkUrl").Select(p => p.Value));
精彩评论