Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Trying to use Saxon.NET for XQuery

2004-09-24
2013-04-25
  • 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).

    Cheers,
    <prs/>
    (Pieter Siegers)

     
  • gstav
    gstav
    2004-09-26

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

     
  • 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();
                dynamicContext.setContextNode(xquery.buildDocument(new javax.xml.transform.stream.StreamSource(new java.io.StringReader(ab.ToString()))));
                //dynamicContext.setContextNode(xquery.buildDocument(new javax.xml.transform.stream.StreamSource(new java.io.StringReader(@"<books><book><title>sdfs</title></book><book></book><book><title>sdfsdf</title></book><book></book></books>"))));
                net.sf.saxon.om.SequenceIterator books = exp.iterator(dynamicContext);
               
                System.Text.StringBuilder _sb = new System.Text.StringBuilder("");
                while (true)
                {
                    
                    net.sf.saxon.om.Item _itm =books.next();     //(net.sf.saxon.om.NodeInfo)
                    if (_itm==null) break;
                    string strItem = _itm.getStringValue();
                    
                    net.sf.saxon.om.NodeInfo _info = (net.sf.saxon.om.NodeInfo)_itm;
                    string strDN = _info.getLocalPart();
                    //net.sf.saxon.om.NodeInfo book =
                    string strBaseuri =_info.getBaseURI();
                    string es = strItem;
    //                if (book==null) break;
    //                string title = book.getStringValue();
                    _sb.Append(strItem.ToString());
                }
                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.

    Cheers,
    <prs/>

     
  • Pieter,

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

    Thanks

    Richard

     
  • 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:

    dynamicContext.setContextNode(xquery.buildDocument(javax.xml.transform.dom.DOMSource(_windowsclientxmldoc)));

    If anyone has any ideas that would be great!

    Thanks!

    Richard

     
  • 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 SF.net 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.

    Cheers!

    &ltM:D/&gt;

     
  • 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 net.sf.saxon.om.SequenceIterator: 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.

    HTH,
    <prs/>

     
  • 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 SF.net before the weekend, so you have something simple to play with :-)

    Cheers,
    <prs/>

     
  • Peiter,

    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!!

    Richard

     
  • 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 !

    Gil

     
  • 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 java.io.StringReader(strSource));

    Questions:
    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 !!

    Thanks

    Gil

     

     
  • 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.

    Cheers,
    <prs/>