Trying to use Saxon.NET for XQuery

  • Richard Amerman

    Richard Amerman - 2004-09-14

    I'm trying to find any examples, documentation (however incomplete), guidance, that can help me get the basics in using this library in a C# project I'm working on.

    Unfortunately I'm facing a deadline and while I might have to just use XPath, because of some more difficult queries I'm needing to do, I would MUCH prefer to use XQuery.

    I was looking into Microsoft's old demo, but the license clearly stats that production use is not allowed, so Saxon is my only hope! (I know, starting to sound too desperate! ;-)

    I have searched exhaustively for anything on the net talking about Saxon.NET and XQuery but found nothing helpful. I have also been pouring over the SaxondotNETwinapp2 example, but it seems to be entirely about doing transforms with XSLT.

    Any help, pointers, or info would be greatly appreciated!!

    Thanks for your time and all your hard work.

    Richard Amerman

    • M. David Peterson

      Hi Richard,

      I am about to reply to your email but wanted to quickly update everyone on what is going on with the project.  MUCH has happened over the last 45 days that had my head spinning so fast as to force the need to take a step back and evaluate things from the outside in.  The good news is that in the next 24-48 hours both a new site and a new release of Saxon.NET will be made available for general consumption.  The bad news... well, there is not really any bad news beyond the fact that because of all that was going on I have ZERO time to communicate this via, the project site, or gotdotnet and as such the project has had the appearance of being somewhat dead.  Pieter returned from vacation about 3 weeks ago and put together a new build and a new sample which helped things seem a little more alive.  But even since that time much has changed and in the technologies that made the speed of this projects development even possible in the first place.

      I will be updating you with more information regarding all of this via the project site (accessible by clicking "Home Page" in the menu above) as soon as I have a chance.

      As far as your questions regarding XQuery specifically I will email you directly with answers to the things we discussed in email.  If you happen to read this in the next bit and you havent recieve the email then plan on receiving it soon.

      Best regards and keep an eye out for the site update and new build availability via the projects RSS or ATOM feeds.

      Best regards,


      • gstav

        gstav - 2004-09-26

        I join ramerman in the immediate interest with c# example with xquery.
        Much appreciated !!

    • Pieter Siegers

      Pieter Siegers - 2004-09-24

      Hi Richard,

      yes, the current example application only showcases XSLT use.

      I am planning to add XQuery and XPath support very soon, but I'm only starting on this, so don't expect anything soon to appear. Sorry about that.

      If you do have something then you always could join us and submit your test sample applications, which we'll then make public (after some testing of course).

      (Pieter Siegers)

    • gstav

      gstav - 2004-09-26

      This I could get, but I need a better way; just to get the xml output without iterations, provided I have a string for the query and xmldocument for the input - wanting an xmldocument for the output.

      Kindly yours.
      Gil Stav

      private void button2_Click(object sender, System.EventArgs e)
                  //string s = qb.ToString().Replace(@"\&quot;"",@"""");
                  Configuration config = new Configuration();
                  StaticQueryContext staticContext = new StaticQueryContext(config);
                  QueryProcessor xquery = new QueryProcessor(staticContext);
                  XQueryExpression exp = xquery.compileQuery(@"<eg>{doc(""books.xml"")//book}</eg>");
                  //XQueryExpression exp = xquery.compileQuery(qb.ToString())

                  DynamicQueryContext dynamicContext = new DynamicQueryContext();
         books = exp.iterator(dynamicContext);
                  System.Text.StringBuilder _sb = new System.Text.StringBuilder("");
                  while (true)
             _itm;     //(
                      if (_itm==null) break;
                      string strItem = _itm.getStringValue();
             _info = (;
                      string strDN = _info.getLocalPart();
                      // book =
                      string strBaseuri =_info.getBaseURI();
                      string es = strItem;
      //                if (book==null) break;
      //                string title = book.getStringValue();
                  string strSb = _sb.ToString();

    • Pieter Siegers

      Pieter Siegers - 2004-09-27

      Hi Gil,

      thanx for sharing your code.

      In .NET, you would call a method that accepts an XmlDocument, and returns the result in another XmlDocument.

      I'll take that approach when implementing XQuery support, in addition to showing it on the screen, and saving it to disk.


    • Richard Amerman

      Richard Amerman - 2004-09-28


      Are you refering to how your going to do the examples you were refering to earlier?



    • Richard Amerman

      Richard Amerman - 2004-09-28

      I was doing some more experimenting trying to do an XQuery with an existing DOM and ran into this issue:

      cannot convert from 'System.Xml.XmlDocument' to 'org.w3c.dom.Node'

      I was trying to use this line:


      If anyone has any ideas that would be great!



    • M. David Peterson

      Hey Richard,

      I am actually just finishing up some sample for the first Saxon.NET beta 1 release based on the 8.1 source code.  A lot of changes have taken place in the base source as well as how they are implmented in Saxon.NET.  With this release I want to make sure that I begin to package up the releases with proper source and documenation as well as samples to go along with it.  As such I have held of on posting it to the server.  None-the-less, I can see things are beginning to build momentum wise and will make extra effort to get the source, binaries, documentation, and sample code posted as soon as possible.

      There is actually a ton to present to the community as far as ideas for what direction we should go next.  Pieter and I have been mulling over this for a while but ideas are beginning to spring forth and I think we have a good foundation to begin building from.

      Let me get this build out and the new site up and then see where we are from there.



    • Cass

      Cass - 2004-10-04

      Just want say, "Keep up the good work."  Finding a port of Saxon for .Net made my day today.

    • Pieter Siegers

      Pieter Siegers - 2004-10-07

      Hi Gilstav,

      if you do not want to iterate and just get the result, read the Saxon documentation provided in the doc directory. A part says this:

      "There are several methods on the QueryExpression object that you can use to achieve this. The evaluate() method returns the result sequence as a Java java.util.List. The evaluateSingle() method is suitable when you know that the result sequence will contain a single item: this returns this item as an Object, or returns null if the result is an empty sequence. There is also an iterator method that returns an iterator over the results. This is a Saxon object of class it is similar to the standard Java iterator, but not quite identical; for example, it can throw exceptions. Finally, there is a run() method, which executes the query, converts the results to an XML document, and writes this document to a JAXP Result object, which may represent a DOM, a SAX ContentHandler, or a serial output stream."

      Personally, I'm working on using the run() method, which should (in my case) just save the result to disk.


    • Pieter Siegers

      Pieter Siegers - 2004-10-07

      Hi all,

      I have got it working - I'll be posting the new example application with support for XSLT 2.0 and XQuery 1.0 here on before the weekend, so you have something simple to play with :-)


    • Richard Amerman

      Richard Amerman - 2004-10-08


      Thanks again for all your hard work!!

      I would not write this or dare ask if I did not have to. It would make a HUGE difference to the project I'm working on if your new XQuery example was to be posted tonight. I'm literally working like mad to get it to work for tomorrow.

      I'm at the office now and will be working on this for the next4-6 hours or more.

      Thanks again for all your work!!


    • gstav

      gstav - 2004-10-08

      Hi Pieter,

      Thanks a lot for your hard work !!
      I am looking forward to using your implementation of Xquery in .net - this is going to be G R E A T !!

      Have a good weekend !


    • gstav

      gstav - 2004-10-11

      Thank a lot again !!
      It works like a Charm !!
      I tried several queries and they all worked perfectly well !!

      The only change I did for my convenience was:
      StreamSource querySource = new StreamSource(new;

      1. Limitations of the Beta.
      2. Scalability:
      I found the following line of code takes 2-3 secs for the first call (only)

      StaticQueryContext staticContext = new StaticQueryContext(config);

      Great work !!




    • Pieter Siegers

      Pieter Siegers - 2004-10-13

      Hi gilstav,

      thanx - great you find it useful! :-)

      A 1. Beta is a beta - use at your own risk. I'm in the process of getting it verified againsta a broad variety of input source documents, both for XSLT 2.0 and XQuery 1.0. This will take a while though.

      A 2. In terms of scalability, we also need to perform tests - but generally, when only the first call means a significant delay, then it is just a matter of fact to pre-compile the project.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks