3
Answers

Read XML file with multiple nodes and display in datagridview

Photo of JR

JR

14y
12.1k
1
Hello,

I have an XML file with the following layout:

    <name>
        <item1>Test</item1>
        <item2>0</item2>
        <info>
            <info1>service</info1>
            <info2>service</info2>
        </info>
    </name>

I use this code to read the XML file:

  string filePath = "C:\\Users\\test\\Desktop\\test.xml";

//XmlTextReader r = new XmlTextReader(filePath);

dsXML.ReadXml(filePath, XmlReadMode.Auto);
dgvXML.AutoGenerateColumns = true;
dgvXML.DataSource = dsXML;
dgvXML.DataMember = "name";

However, I only get the following columns in the datagridview:

item1
item2

but I would like to see:

item1
item2
info1
info2

What am I doing wrong?

Thanks in advance.

Answers (3)