The end goal is to be able to query an XML file that has been provided by a third party. I need to be able to query each element to return its results. I am not stuck on the idea of reading it into a dataset, however, for me it just seems to be the easiest solution.
Input XML Full XML On GitHub
My XML File has 14 xmlns's and a xsi, when I attempted to read the XML File into a dataset:
DataSet myset = new DataSet();
myset.ReadXml(_fileName);
I get an error message: System.Data.DuplicateNameException: 'Cannot add a column named 'IncidentAugmentation': a nested table with the same name already belongs to this DataTable.'
It is obvious that the "IncidentAugmentation" element already exist in the XML, however, it is in a different xmlns.
Using XDocument to query the XML, I want to search all reports where the "IncidentAugmentation" value = "N", but when I run the following results, I get 0 returns, and two returns are expected.
XDocument submissions = XDocument.Load(_fileName);
var allReportsWithClearCodeN = submissions.Elements("IncidentAugmentation")
.Where(m => m.Element("IncidentExceptionalClearanceCode").Value == "N");
While I am not positive if the xmlns's are the issue, that is where I have been focusing my attention.
How am I able to better import that XML File into a DataTable or a quarriable format? or am I just way off in my methodology?
I wanted to post the answer given to me by Yizhak because for me, finding the answer was extremely difficult.
The issue I was having is getting an XML File into a format that I could query. Turns out that the easiest way to do this is through Microsoft SQL Server Management Studio.
Prerequisite
You must have ADMINISTER BULK OPERATIONS or be a member of the fixed server role, bulkadmin, on the SQL Server. Also, the XML File MUST be on a network share or directly on the SQL Server.
Procedure
Login to SSMS and open a new Query Window and enter the following:
Again, I want to thank Yizhak for helping me with this.