Link XML file to a datagrid

  • Thread starter Thread starter Hugh Creswell
  • Start date Start date
H

Hugh Creswell

Hi there, I wonder if anyone can give me some help here?
I am a newbie at csharp, and am translating a C++ app that I wrote into
csharp.
What I have is a and XmlDocument in memory, referenced by a variable

m_loadedFile = new XmlDocument();

This is then loaded from an Xml file, whose structure looks something like
this (for brevity, I know this isnt fully formed!) :-

<top_level>
<something_0>
<level_1>
<level_2>
<field_1>data 1</field_1>
<field_2>data 2</field_2>
<field_3></field_3>
<field_4></field_4>
<field_5>data 5</field_5>
<field_6>data 6</field_6>
<field_7>data 7</field_7>
</level_2>
</level_1>
<level_1>
<level_2>
<field_1>data 1</field_1>
<field_2>data 2</field_2>
<field_3></field_3>
<field_4></field_4>
<field_5>data 5</field_5>
<field_6>data 6</field_6>
<field_7>data 7</field_7>
</level_2>
</level_1>
<something_0>
<something_1>
</something_1>
<something_2>
</something_3>
</top_level>

What I would like to do is link the level_1 data as rows in a datagrid, with
the field data becoming the cells in the datagrid. When I save the datagrid,
I woudl like the level_1 data updated ( I will then save the Xml document at
a later point)

I think that I have to setup datasets and the like, but after looking at
various sites such as codeguru, csharphelp etc, I am really confused! So any
help woudl really be appreciated.

Thanks in advance

Hugh
 
Hugh,

You could load the XML into a dataset and bind a DataGrid control to that
dataset. The structure of your XML, however, seems to be not that easily
inferrable. Try DataSet.ReadXml with XmlReadMode.InferSchema, and if that
does not help, we will think of something else.
 
Back
Top