Jibrohni Posted October 13, 2010 Posted October 13, 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. //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 Quote
Jibrohni Posted October 13, 2010 Author Posted October 13, 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>(); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.