How do I choose only the xml items that have the "Action" elements

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Here is my code. I load the XML and try to get only the entries that have Action element. I end up getting all the entries instead.
XElement root = XElement.Load(path)
IEnumerable<XElement> items =
from el in root.Elements("ReportInfo")
where el.Elements("Action") != null
select el;
foreach (XElement el in items)
{
navInfo navinfo = new navInfo();
navInfo.Id = int.Parse(el.element("Id").Value);
......
}
__________________________________________________
The XML file is:
<NavigationItems>
<ReportInfo><br/>
<Id>31</Id><br/>
<Name>ReportAdAnalysis</Name><br/>
<Description>ReportAdAnalysisDescription</Description><br/>
<Action>ReportAdAnalysis MVC action method name</Action><br/>
</ReportInfo><br/>
<ReportInfo><br/>
<Id>32</Id><br/>
<Name>ReportMediaLog</Name><br/>
<Description>ReportMediaLog Description</Description><br/>
<Url>ReportMediaLog URL </Url><br/>
</ReportInfo><br/>
<ReportInfo><br/>
<Id>33</Id><br/>
<Name>ReportClutterReport</Name><br/>
<Description>ReportClutterReport Description</Description><br/>
<Action>ReportClutterReport MVC action method name</Action><br/>
</ReportInfo><br/>
<ReportInfo><br/>
<Id>40</Id><br/>
<Name>ReportNationalMscore</Name><br/>
<Description>ReportNationalMscore Description </Description><br/>
<Url>ReportNationalMscore URL</Url><br/>
</ReportInfo>
</NavigationItems>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small



View the full article
 
Back
Top