Skip to content

C# XML parse

Haffiz Momodu

Asked Feb 16, 2011, 6:17 AM EST3 answers
Share
LinkedInX

I am finding it difficult to loop through a table using C# and output the file in XML to my anticipated format. Here is what I am trying to achieve.  Let us assume my data (table) is below.

 

col1, col2

A    ,   1

A    ,   2

A    ,   3

B    ,   1

B    ,   2

C    ,   1

 

My xml output file should be something like

 

A, 1, 2, 3

B, 1, 2

C, 1

 

In other words if col1 repeats itself in the table then append col2. The example above seems straightforward but it is not the exact situation. The exact situation is in the attachments below.

I have attached the original access database (db.accdb) that contains the tables, C# code (C#-code), xml output file after running the C# code (XML_data.xml), and anticipated output file (XML_data-Want.xml).

The anticipated output file (XML_data-Want.xml) is the exact data I am trying to output using C#.

Any help is greatly appreciated. Please do not just suggest answers. Provide the solution by giving me the exact C# code.

 

Thanks again.

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    I have resloved my problem.

    Thanks!
    0
  • Suthish Nair
    0
    can you post the solution also here, helpful for the others.
    0
  • 0
    Attached is the C# code (C#-code.zip) for the solution. Note in this case I used TableAdapters instead of OLEDB. It doesn't not matter which ever connection is used.

    Regards,
    Haffiz Momodu
    0