I'm using LINQPad to query and visualize XML files with C#. For example:
var xml = XElement.Load(@"C:\file.xml");
xml.Elements().Where(e => e.Element("trHeader").Element("trTickNum").Value == "1").Dump();
However, I'd like run a query using SQL rather than C#.
Is there a way to load an XML which contains nested elements and query its table(s) using LINQPad's SQL option?
This works for me.
var xml = XElement.Load(@"C:\AllTypesList.xml");
var list = xml.Elements().ToList();
var types = list.Where(x => x.Name == "XmlParamType").ToList();
types.Count().Dump();
types.GroupBy(t => t.Element("TypeName").Value).Count().Dump();
That's not possible. The SQL option requires a database to be specified and is used to query that database. It's not possible to use SQL against an XML file which has its own hierarchy. What you could do is figure out a way to load the XML into SQL, or use the XML data type in SQL, then operate on the data entirely using SQL statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With