Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

 

//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();
               
           }

example.txt

Posted

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>();

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...