Take care your structure here is not valid XML for XElement.Parse, because your elements do not have a name, but only attributes.
Possible correct structure:
<Instances> <Image Bits = "16" XCoord = "64" YCoord = "64" ZCoord = "64" FileType="jpeg" Location="C:\Series1\Image1.jpg" ImageNumber = "1" /> <Image Bits = "16" XCoord = "64" YCoord = "64" ZCoord = "64" FileType="jpeg" Location="C:\Series1\Image2.jpg" ImageNumber = "2" /> <Image Bits = "16" XCoord = "64" YCoord = "64" ZCoord = "64" FileType="jpeg" Location="C:\Series1\Image3.jpg" ImageNumber = "3" /> <Image Bits = "16" XCoord = "64" YCoord = "64" ZCoord = "64" FileType="jpeg" Location="C:\Series1\Image4.jpg" ImageNumber = "4" /> <Image Bits = "16" XCoord = "64" YCoord = "64" ZCoord = "64" FileType="jpeg" Location="C:\Series1\Image5.jpg" ImageNumber = "5" /> </Instances>
This will cause C # Code for Parsing to be based on Jon Skeet code on top:
XElement root = XElement.Parse(text); List<string> images = root.Elements("Image") .Select(x => (string) x.Attribute("Location")) .ToList();
Hth :)
source share