1

I'm attempting to ingest multi-layered XML data from an API in order to insert it into a database.

Firstly, once I've pulled the XML file from the API, I'm using DataSet's ReadXML method to create DataTables. There happens to be 19 in total within the DataSet once ingested.

I understand that I can use DataRelation to link all of the tables, but it looks like the ReadXML method has already inferred some schema info and thus generated what appear to be sensible relationships between each DataTable of the DataSet.

However, I'd like to end up with just one table to port into my database, not 19, and I'd prefer to join/merge/relate the tables in C#, instead of within SQL.

Can you advise on a best practice for creating a single table from all related DataTables within my current DataSet?

  • ReadXML doesn't work well when you have multilevel xml. The root tag is the dataset name. Next tag is table name. Next tags are the column names. Any more levels of tags creates a mess of new datatables. You got 19 tables because of the depth of the xml tags. It is better to parse xml in code to get a single table then attempt to join the mess that ReadXML created. – jdweng May 13 '16 at 09:17
  • Hi, jdweng. Thanks for your feedback. Can you recommend the best way to parse the XML in code to get a single table? I'm not very comfortable working with XML and C# together yet. – Joseph Jeremiah Noonan May 15 '16 at 02:15
  • the are a few methods for parsing xml and it depends on a number of factors. I can't give a best method without seeing the xml, but I normally use Xml Linq for most parsing. For large xml files I use a combination of XMLReader and xml Linq. – jdweng May 15 '16 at 11:11

0 Answers0