Read values from xml and add them into list



How to read the values (image1, image2, image3) from this xml file. Its a sample and I dont know about the number of values exactly. I mean maybe the xml file has more Image Name . I want to add these images name into a list. and also I want to get ImageInterval value and set it into int variable.



<Sinage DataBase>

<Image>
<ImageName>
image1
</ImageName>

<ImageName>
image2
</ImageName>

<ImageName>
image3
</ImageName>

<ImageInterval>
4
</ImageInterval>
</Image>
</Sinage DataBase>


Its my list:



public List<string> ImageName { get; set; }


I used above code for reading data but display error : Illegal character in path


XDocument doc = XDocument.Load(global::TestGraphic.Properties.Resources.xml);



var ImageName = doc.Descendants("ImageName");

foreach (var image in ImageName)
{
MessageBox.Show(image.Value);
}

No comments:

Post a Comment