LINQ syntax help

Jibrohni

Freshman
Joined
Apr 15, 2010
Hi all,

I'm trying to retrieve some specific data from an XML file I have attached. The data is in <LinkCollection>



I have a semi populated class object that contains an ID that directly relates to the LinkItem ID. Matching these values I then want to populate the rest of the class with the other data - Path, Index and any DescriptiveText held under that ID.

My attempt is here but I'm returning dodgy string values and getting nowhere slowly.

Code:
//gets icon path and index
            foreach (LinkItem item in linkItems)
            {
                var Index = from LinkIcon in xmlDoc.Descendants("LinkIcon")
                            where (string)LinkIcon.Parent.Attribute("ID") == item.LinkID
                            select LinkIcon.Attribute("Index").Value;
                item.IconIndex = Index.ToString();

                var Path = from LinkCollection in xmlDoc.Descendants("LinkItem")
                           where LinkCollection.Attribute("ID").Value == item.LinkID
                           select LinkCollection.Descendants("LinkIcon").Attributes("Path");
                item.IconPath = Path.ToString();
                
            }
 

Attachments

  • example.txt
    630 bytes · Views: 0

Jibrohni

Freshman
Joined
Apr 15, 2010
SOLVED:

var Index = from LinkIcon in xmlDoc.Descendants("LinkIcon")
where (string)LinkIcon.Parent.Attribute("ID").Value == item.LinkID.ToString()
select LinkIcon.Attribute("Index").Value;
item.IconIndex = Index.First<string>();

var Path = from LinkCollection in xmlDoc.Descendants("LinkIcon")
where (string)LinkCollection.Parent.Attribute("ID").Value == item.LinkID.ToString()
select LinkCollection.Attribute("Path").Value;
item.IconPath = Path.First<string>();
 
Top Bottom