How to find other attribute value corresponding searced attribute

A

Andrus

Header("Item1")

returns

<MenuItem Content="Open file" Name="Item1" />

How to change this so it returns Content attribute value "Open file"
corresponding to Name attribute value ?

public static string Header(string entity) {
return Menu.Descendants("MenuItem").Where(m =>
(string)m.Attribute("Name") == entity).Single().ToString();
}

Menu type is XElement and it contains:

<Menu>
<MenuItem Content="File">
<Items>
<MenuItem Content="FilemenuSubMenu1">
<Items>
<MenuItem Content="Open file" Name="Item1" />
<MenuItem Content="Save" Name="Item2" />
.....
<MenuItem IsSeparator="true" />
.....
</Items>
</MenuItem>
<MenuItem Content="FilemenuSubMenu1">
<Items>
.....
</Menu>

Andrus.
 
A

Arne Vajh¸j

Header("Item1")

returns

<MenuItem Content="Open file" Name="Item1" />

How to change this so it returns Content attribute value "Open file"
corresponding to Name attribute value ?

public static string Header(string entity) {
return Menu.Descendants("MenuItem").Where(m =>
(string)m.Attribute("Name") == entity).Single().ToString();
}

Try:

Menu.Descendants("MenuItem").Where(m => (string)m.Attribute("Name") ==
entity).Single().Attribute("Content").Value

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top