我正在尝试解析一个mvcSiteMap,我已经完成了大部分工作,但我的where子句不对。它总是返回where子句应该排除的行。
nodeTitle = "Bulk Order Request";
XElement xelement2 = XElement.Load( filePath );
var urlDescList1 = (xelement2.Descendants()
// Select node with 'Favorite Social Sites'
.Where( node => ( string ) node.Attribute( "title" ).Value != nodeTitle )
.SelectMany( node => node.Elements() )
.Select( node => new
{
title = node.Attribute( "title" ).Value,
url = node.Attribute( "action" ).Value
} )).ToList();
无论where子句是否存在,我都会返回相同数量的行。 它就像where子句总是为true,即使输出的lsit的title元素包含“Bulk Order Request”作为其'title
我确定我做了一些Obvioulsy愚蠢的事,但我看不到它。
谢谢,
埃里克 -
XML
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-1.0">
<mvcSiteMapNode title="Home" controller="Home" action="Index" isDynamic="true" dynamicParameters="*" >
<mvcSiteMapNode title="Home" controller="RunWebForm" action="DisplayPage/~-Scout_Main-HelloPage.aspx" roles="*" />
<mvcSiteMapNode title="Inbond Call" controller="RunWebForm" action="DisplayPage/~-Scout_HandleCall-StartCall.aspx" roles="*" />
<mvcSiteMapNode title="Reports" controller="NoController" action="NoAction/80" roles="*" >
<mvcSiteMapNode title="Activity By Type" controller="Reports" action="ActivityByType" roles="*" />
<mvcSiteMapNode title="Activity By Agent" controller="Reports" action="ActivityByAgent" roles="*" />
<mvcSiteMapNode title="Activity By Language" controller="Reports" action="ActivityByLang" roles="*" />
<mvcSiteMapNode title="Complaints" controller="Reports" action="ComplaintReport" roles="*" />
<mvcSiteMapNode title="Volume by Date Time" controller="Reports" action="VolumeByDateTime" roles="*" />
<mvcSiteMapNode title="Activity By Gender" controller="Reports" action="CallPersonActivityByGenderReport" roles="*" />
<mvcSiteMapNode title="Prospects by Age" controller="Reports" action="ActivitybyProspectsbyAge" roles="*" />
<mvcSiteMapNode title="Prospects by Ethnicity" controller="Reports" action="ActivitybyEthnicity" roles="*" />
<mvcSiteMapNode title="Prospects by Gender" controller="Reports" action="ActivitybyGender" roles="*" />
<mvcSiteMapNode title="Prospects by Language" controller="Reports" action="ActivitybyLanguage" roles="*" />
<mvcSiteMapNode title="Activity by Referral Source" controller="Reports" action="ActivitybyReferralSource" roles="*" />
</mvcSiteMapNode>
<mvcSiteMapNode title="Fullfillment letter" controller="NoController" action="NoAction/9" roles="*" >
<mvcSiteMapNode title="Bulk Order Request" controller="Reports" action="ActivityByBulkOrderRequest" roles="*" />
<mvcSiteMapNode title="Letter English" controller="Reports" action="LetterEnglish" roles="*" />
<mvcSiteMapNode title="Letter English - General Inquiry" controller="Reports" action="LetterEnglishForGeneralInquiry" roles="*" />
</mvcSiteMapNode>
<mvcSiteMapNode title="Maintenance" description="Maintenance" controller="NoController" action="NoAction/11" roles="4048">
<mvcSiteMapNode controller="RunWebForm" action="DisplayPage/~-Scout_Main-Administration-MaintainScripts.aspx" title="Maintain Call Scripts " description="Maintain Call Scripts" roles="4048"/>
<mvcSiteMapNode controller="RunWebForm" action="DisplayPage/~-Scout_Main-Administration-MediaTypeMaintain.aspx" title="Maintain Media Items " description="Maintain Media Items" roles="4048"/>
<mvcSiteMapNode controller="RunWebForm" action="DisplayPage/~-Scout_Main-Administration-CallMainSource.aspx" title="Maintain Call Main Sources " description="Maintain Call Main Sources" roles="4048"/>
<mvcSiteMapNode controller="RunWebForm" action="DisplayPage/~-Scout_Main-Administration-CallSecondarySource.aspx" title="Maintain Call Secondary Sources " description="Maintain Call Secondary Sources" roles="4048"/>
<mvcSiteMapNode controller="RunWebForm" action="DisplayPage/~-Scout_Main-Administration-CallOtherLanguage.aspx" title="Maintain Additional Languages" description="Maintain Additional Languages" roles="4048"/>
</mvcSiteMapNode>
<mvcSiteMapNode controller="Account" action="Logon" title="Logout" description="Logout and return to the login screen" roles="*" />
</mvcSiteMapNode>
</siteMap>
答案 0 :(得分:1)
重写了非lambda工作正常
XElement xelement2 = XElement.Load( filePath );
var query = from c in xelement2.Descendants()
where (string)c.Attribute("title").Value != nodeTitle
select c;