- You can download the class library from here.
- After downloading the file just move .dll file to your project`s bin folder.
- As last step you need to add this .dll file as reference to your project.
After doing all these steps you will be able to use this library in your project. Also you should attach it to your code like:
using Microsoft.Xml.XQuery;
First, we need to create XQueryNavigatorCollection instance:
XQueryNavigatorCollection col = new XQueryNavigatorCollection();
Then we need to link the xml data file to our instance, AddNavigator method`s first input will be the path of the data file and second one is the alias of that file. This alias will be useful while writing our XQuery to point out our data file.
col.AddNavigator(Server.MapPath("Data.xml"), "doc");
We are writing our XQuery and assign it to a string value, as you can see I used "doc" alias that points Data.xml file:
string query = "for $row in document(\"doc\")/Import/Row " +
"return " +
"$row";
After assigning our query to a string we give this string to XQueryExpression class`s constructor, by doing this step our query will be ready to be executed:
XQueryExpression xepr = new XQueryExpression(query);
To execute our query and get the output from it we are just writing:
string result = xepr.Execute(col).ToXml();
and getting the result to string result variable. By getting the result you can do whatever you want with it. You can just display it as it is or by assigning it to a DataSet you can give to it more usable scope in your project.
After a while I will post how can you assign it to a DataSet...
