Ruchir Saxena

Ruchir Saxena

  • NA
  • 3.2k
  • 3.4k

Linq to XML

Sep 12 2014 3:36 AM
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--Creating an XML Tree for Navigation Menu-->
<NavigationDetails>
<Navigation Type="SubMenu">
<Node Text="Langrennsbindinger Skøyte" Value="1060402" />
<Node Text="Rulleskipigger" Value="1061304" />
<Node Text="Terrengsykkel Herre" Value="1010101" />
</Navigation>
<Navigation Type="MainMenu">
<Node Text="Komplette rulleski" Value="1061301" />
<Node Text="Rulleskihansker" Value="1061303" />
<Node Text="Sykkel" Value="1" />
</Navigation>
</NavigationDetails>
 
----------------------------------------------------------------
In the above xml document how can i find  the following result where -Type="SubMenu"
 
Text="Langrennsbindinger Skøyte" Value="1060402" 
 Text="Rulleskipigger" Value="1061304"
 Text="Terrengsykkel Herre" Value="1010101"
 
--My Query Attempt--
XDocument xmlDoc_region = XDocument.Load(PathofXML);
var list_category = from nodeitem in xmlDoc_region.Elements("Navigation")
where nodeitem.Attribute("Type").Value == "MainMenu"
select new
{
CategoryName = nodeitem.Element("Node").Attribute("Text").Value,
CategoryId = nodeitem.Element("Node").Attribute("Value").Value
};
 
 
 
 
 
 
 

Answers (2)