我想通过在linq中给出linktext(Last 3 Month)和SecondaryLink linkid s14来读取navlinks(l63)的链接ID:
<SecondaryLink>
<LinkID>
<![CDATA[s14]]>
</LinkID>
<LinkText>
<![CDATA[All Brands]]>
</LinkText>
<LeftMenu>
<NavLinks>
<LinkID>
<![CDATA[l63]]>
</LinkID>
<LinkText>
<![CDATA[Last 3 Months]]>
</LinkText>
</NavLinks>
</LeftMenu>
</SecondaryLink>
这就是我所拥有的,我想再给一个条件。
string secondaryid = doc.Descendants()
.Elements("LinkText")
.Where(x => x.Value == "Last 3 Months")
.Single()
.Parent
.Element("LinkID").Value;
即 linkid=s14
var q = from c in xml.Descendants("SecondaryLink")
where (string)c.Element("LinkID") == "s14"
where (string)c.Element("LeftMenu").Element("NavLinks").Element("LinkText") == "Last 3 Months"
select c.Element("LeftMenu").Element("NavLinks").Element("LinkID");