-1

i have XML File :

<?xml version="1.0" encoding="utf-8"?>
<!--XML Database.-->
<Disease>

<Name id="1">Info1
<SubArticle>Info1</SubArticle>
<MainArticle>Info1</MainArticle>
<Image>Info1</Image>
</Name>

<Name id="2">Info2
<SubArticle>Info2</SubArticle>
<MainArticle>Info2</MainArticle>
<Image>Info2</Image>
</Name>

<Name id="3">Info3
<SubArticle>Info3</SubArticle>
<MainArticle>Info3</MainArticle>
<Image>Info3</Image>
</Name>

</Disease>

and i have UserControl :

enter image description here

and i have a FlowLayoutPanel which have an FlowDirection (TopDown)

I need to make the program add new UserControl in the FlowLayoutPanel with the Information in the XML File Examble: The Program will add 3 UserControl in the Panel

UserControl1 =  <Name id="1">
UserControl2 =  <Name id="2"> 
UserControl3 =  <Name id="3"> 

...etc

How can i do this ?

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • 1
    Please show what you have tried. Currently, it's not even clear whether you have trouble reading the file or changing the control. – GolezTrol Jun 13 '15 at 11:31
  • the propem not in the user control , but i need a code read all elements in the xml file and show it in the labels in usercontrol – Mohamed Saied Jun 13 '15 at 11:36
  • 2
    The 'and' in your sentence indicates that they are two separate problems. If you approach them as such you may very well find the answers to them (1, How to read an XML file and 2, How to show a text in a label in a usercontrol). After that, you can simply combining by using the output of 1 as the input of 2. – GolezTrol Jun 13 '15 at 11:38
  • i know how to read xml file but all the usercontrols will get the information only from the first element – Mohamed Saied Jun 13 '15 at 12:14
  • i mean how can i make a loop get the info from the xml ? – Mohamed Saied Jun 13 '15 at 12:22

1 Answers1

0

Try this

Imports System.Xml
Module Module1

    Const FILENAME As String = "c:\temp\test.xml"
    Sub Main()
        Dim doc As New XmlDocument
        doc.Load(FILENAME)
        Dim names As XmlNodeList = doc.GetElementsByTagName("Name")

        Dim diseases As New List(Of Disease)
        For Each name As XmlNode In names
            Dim newDisease As New Disease
            diseases.Add(newDisease)

            newDisease.id = name.Attributes("id").Value
            newDisease.text = name.InnerText
            newDisease.subArticle = name.SelectSingleNode("SubArticle").InnerText
            newDisease.mainArticle = name.SelectSingleNode("MainArticle").InnerText
            newDisease.image = name.SelectSingleNode("Image").InnerText


        Next

    End Sub

    '  <Name id="1">
    '  Info1
    '  <SubArticle>Info1</SubArticle>
    '  <MainArticle>Info1</MainArticle>
    '  <Image>Info1</Image>
    '</Name>

End Module
Public Class Disease
    Public id As Integer
    Public text As String
    Public subArticle As String
    Public mainArticle As String
    Public image As String
End Class
​
jdweng
  • 33,250
  • 2
  • 15
  • 20
  • thanks for the code , but i have 1 proplem , how can i put the image in the xml file in a picture box , i get error (cannot convert string to drawing.image ? – Mohamed Saied Jun 13 '15 at 13:35
  • Does the XML contain image? You need to change type in class from string to image. I just used string because that is what you posted. – jdweng Jun 13 '15 at 14:04
  • no the xml will have the path of the image , so how can i change the path (String) into image (System.Deaw) ? – Mohamed Saied Jun 13 '15 at 14:29
  • See webpage : http://stackoverflow.com/questions/14360257/convert-byte-to-image. You need to use Image.FromStream(). String to image usually give problems, use byte[] instead. – jdweng Jun 13 '15 at 14:44
  • i solve it by using Article.PictureBox1.Image = Image.FromFile(newDisease.image) thank you for the code – Mohamed Saied Jun 13 '15 at 16:11