I need to create a console app on C# which creates BaseX DB based on a certain xml file and then outputs this file on the console. I've figured out how to connect, create and then make a query to output this file in the BaseX client and BaseX GUI however in my Console app it doesn't output the xml file.
My code is: `
using System;
using System.Diagnostics;
using System.IO;
using BaseXClient;
namespace LR4_BaseX
{
class Program
{
static void Main(string[] args)
{
BaseXClient.Session session = new Session("localhost", 1984, "admin", "admin");
BaseXClient.Query query;
string sqry = "CREATE DATABASE myDB C:/DB/PRIM/BOOKS/books.xml";
session.Query(sqry);
sqry = "FIND FOR $x IN //CATALOG RETURN $x/book";
query = session.Query(sqry);
Console.WriteLine(query);
query.Close();
session.Close();
Console.ReadKey();
}
}
}
Console outputs a string: "BaseXClient.Query" instead of the file, while the exact same queries in BaseX client do output my file:[BaseX Client results](https://i.stack.imgur.com/gIbaS.png) When I tried to play around query, I changed output fragment to one I saw in official documentation:
while (query.More())
{
Console.WriteLine(query.Next());
}
` But with this code, it doesn't compile with the Error: "Stopped at ., 1/6: [XPST0003] Unexpected end of query: '$x IN //CATALOG...'." What do I change to output my xml file?
Problem solved. I've changed query to output xml file to:
sqry = "db:get-pre(\"myDB\", 0)/*:catalog/book"; query = session.Query(sqry); Console.WriteLine("xml:" + query.Execute());Now it works just fine. P.S. Also I'd like to mention in case somebody tries to compile app from a .bat file or can't compile it from VS because of some "netstandart2.0" problem, you just have to add a reference to this lib, works fine with Framework 4.5.2 Result