I need to upload a picture from an XML code into a PictureBox .

 <image> <title>Yahoo! Weather</title> <width>142</width> <height>18</height> <link>http://weather.yahoo.com</link> <url>http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif</url> </image> 

Please help me understand how to do this.

  • WinForms project? - Sá´‡M
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky ♦

1 answer 1

I used LINQ to XML :

 using System.Xml.Linq; 

Load the source xml file:

 XDocument xdoc = XDocument.Load(@"C:\Users\admin\Documents\test.xml"); 

Get the data of the desired tag (picture address):

 XElement picElement = xdoc.Root.Element("url"); 

Show picture:

 pictureBox1.ImageLocation = picElement.Value; 

This is if the xml structure is:

<?xml version="1.0" encoding="UTF-8"?> <image> <title>Yahoo! Weather</title> <width>142</width> <height>18</height> <link>http://weather.yahoo.com</link> <url>file:///C:/Users/admin/Pictures/ku.jpg</url> </image>

If harder, read here 1 2