0

Currently, we generate a shipping manifest file using VBA. I was able to take care of the grunt work of harmonizing, and getting the dataset I need, converted to C#, my last step is to generate the XML file in C# is as well.

The way it works currently, VBA opens a recordset called tblXMLcodes which has 4 fields, Tag, Carrier, Section, and orderct.. Tag has each tag I need, carrier is always the same, section is either Item, or Package as I have two data sets (a package query and an item query) Then the orderct field is just numbered 1-16 for each section.

Then another record set is opened from the item query AND the package query and it gets looped through appending to a .txt file..

How can I easily take my two datasets (both queries) and loop through them to generate an XML file..

Are there any NuGet packages?

Any help is appreciated.. Currently my code works so I wont post it, but if someone wants to see the current I will gladly share. It is VERY slow....

  • I you have already a C# DataSet instance created (System.Data.DataSet) and populated with your data you can use a StreamWriter and write an XML using the data set WriteXml function: https://stackoverflow.com/questions/5259759/how-can-i-convert-a-datatable-to-an-xml-file-in-c – Ph0b0x Sep 13 '18 at 15:38
  • I need to be able to control exactly what tag says what, should I use xDocument instead? – Tyler James Sep 13 '18 at 15:40
  • Did you try using XmlDocument? – Ph0b0x Sep 13 '18 at 15:42

1 Answers1

0

follow this code

DataSet ds = new DataSet();
ds.Tables.Add(dt1); // Table 1
ds.Tables.Add(dt2); // Table 2...
...
string dsXml= ds.GetXml();
...
using (StreamWriter fs = new StreamWriter(xmlFile)) // XML File Path
{
      ds.WriteXml(fs);
}
  • that's the code from the URL i shared. I think it's not the solution based on Tyler's comment. – Ph0b0x Sep 13 '18 at 17:09