From the course: LINQPad Essential Training

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Configure an XML file as a data source

Configure an XML file as a data source - LINQ Tutorial

From the course: LINQPad Essential Training

Configure an XML file as a data source

- Another SQL source is XML data. We can work with any valid XML string as the source. For my example, I'm working with the content of this XML file, this RobotName.xml. This is in the assets folder for the course so you can find it by going to open, go to assets, show all files, it's this file here. Let's take a look at the contents of this file. It starts with one root node called Robots, and then there are 12 of these children elements robot, and then there are some nested elements, robot name and weight, their child elements of robot, and there's also an attribute for each robot team-name. How do you load this into a SQL. That's what we have over here. So the first thing we need to do is load the XML into a query able type. For this example, I'm using this XElement type, which represents an XML element. So the top part of this code is creating the path to load the file. So on line three, I'm using…

Contents