List<XNode> retrieve certain Attribute

I have the following event:

private void listBox_Items_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (listBox_Items.SelectedIndex > -1)
        {
            XDocument xDoc = XDocument.Load(FileName);

            var doc = xDoc.Descendants("item")
                          .Where(x => x.Attribute("id").Value == listBox_Items.Text)
                          .Select(x => x.Nodes())
                          .SelectMany(x => x.ToList())
                          .ToList();
            XNode name = doc[0];
            XNode id = doc[1];
        }
    }

I have gotten XNode name = doc[0]; to give me <name value="Ruby Pouch I" /> but I'm looking to get just Ruby Pouch I

Any feedback is appreciated!

Jon Skeet
people
quotationmark

If you're just trying to select the value attribute, you should do that:

var values = xDoc.Descendants("item")
                 .Where(x => x.Attribute("id").Value == listBox_Items.Text)
                 .Select(x => x.Attribute("value").Value)
                 .ToList();

There's no need to call Nodes() or SelectMany at all.

people

See more on this question at Stackoverflow