Hi there,

I am new to this forum so please be patient with me :-)
My problem is how to bring a nested XML structure into a single DataGridView. The XML looks like this:

<Artist>
    <Name>John Doe</Name>
    <Age>36</Age>
    <Language>english</Language>
    <Artwork>
        <Picture>Picture 10</Picture>
        <Picture>Picture 20</Picture>
        <Picture>Picture 30</Picture>
    </Artwork>
</Artist>
<Artist>
    <Name>Mike Smith</Name>
    <Age>51</Age>
    <Language>english</Language>
    <Artwork>
        <Picture>Picture 11</Picture>
        <Picture>Picture 21</Picture>
        <Picture>Picture 31</Picture>
        <Picture>Picture 41</Picture>
        <Picture>Picture 51</Picture>
        <Picture>Picture 61</Picture>
    </Artwork>
</Artist>

All I would like to do is populating a DataGridView with 4 columns (Name, Age, Language and Artwork). Each of which containing its appropriate value whereas the latter will contain all pictures... See what I mean?

Please assist.

Cheers, Tommy

kvprajapati commented: Welcome :) Good question! +14

There are number of methods/APIs to parse XML document in .net framework but I'd like to use & suggest Linq-Xml.

Have a look at SSCCE:

Dim file = "c:\folder\data.xml"
Dim doc = XDocument.Load(file)

Dim Result = From ele In doc.Root.Descendants("Artist")
                     Select New With
                      {
                       .Name = ele.Element("Name").Value,
                       .Age = ele.Element("Age").Value,
                       .Language = ele.Element("Language").Value,
                       .Images = ele.Elements("Artwork").Select(Function(p)
                                                                 Return p.Value
                                                                End Function).ToList()}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.