Project

Profile

Help

Error while parsing XQuery

Added by Anonymous about 19 years ago

Legacy ID: #3095924 Legacy Poster: ali (cfsdevln)

Hi, I am using SAXON.NET and trying to parse an XQuery but I keep getting an exception of "Object reference not set to an instance of an object". The code seems ok. Any ideas? The code and exceptions follows: net.sf.saxon.Configuration config = new Configuration(); StaticQueryContext env = new StaticQueryContext(config); StreamReader sr = new StreamReader("C:\mul.xq"); string xquery = sr.ReadToEnd(); net.sf.saxon.query.QueryParser qp = new QueryParser(); net.sf.saxon.expr.Expression exp = qp.parseQuery(xquery, 0, 0, env); --------------------------- Object reference not set to an instance of an object. at net.sf.saxon.query.StaticQueryContext.getLocationMap() at net.sf.saxon.expr.ExpressionParser.setLocation(Expression exp, Int32 offset) at net.sf.saxon.query.QueryParser.parseDirectElementConstructor() at net.sf.saxon.query.QueryParser.parsePseudoXML(Boolean allowEndTag) at net.sf.saxon.query.QueryParser.parseConstructor() at net.sf.saxon.expr.ExpressionParser.parseBasicStep() at net.sf.saxon.expr.ExpressionParser.parseStepExpression() at net.sf.saxon.expr.ExpressionParser.parseRelativePath() at net.sf.saxon.expr.ExpressionParser.parsePathExpression() at net.sf.saxon.expr.ExpressionParser.parseUnaryExpression() at net.sf.saxon.expr.ExpressionParser.parseCastExpression() at net.sf.saxon.expr.ExpressionParser.parseCastableExpression() at net.sf.saxon.expr.ExpressionParser.parseTreatExpression() at net.sf.saxon.expr.ExpressionParser.parseInstanceOfExpression() at net.sf.saxon.expr.ExpressionParser.parseIntersectExpression() at net.sf.saxon.expr.ExpressionParser.parseUnionExpression() at net.sf.saxon.expr.ExpressionParser.parseMultiplicativeExpression() at net.sf.saxon.expr.ExpressionParser.parseAdditiveExpression() at net.sf.saxon.expr.ExpressionParser.parseRangeExpression() at net.sf.saxon.expr.ExpressionParser.parseComparisonExpression() at net.sf.saxon.expr.ExpressionParser.parseAndExpression() at net.sf.saxon.expr.ExpressionParser.parseOrExpression() at net.sf.saxon.expr.ExpressionParser.parseExprSingle() at net.sf.saxon.expr.ExpressionParser.parseExpression() at net.sf.saxon.query.QueryParser.parseQuery(String queryString, Int32 start, Int32 terminator, StaticQueryContext env) at SaxondotNETwinappbetav04Sax811B.Form1.button1_Click(Object sender, EventArgs e) in c:\documents and settings\mali\desktop\saxondotnetwinappbetav04sax811b\form1.cs:line 1022 --------------------------- OK ---------------------------


Replies (6)

Please register to reply

RE: Error while parsing XQuery - Added by Anonymous about 19 years ago

Legacy ID: #3095942 Legacy Poster: Michael Kay (mhkay)

Sorry, but this is not the correct place to report problems with Saxon.NET, which is outside the scope of this project. I'm not sure what mechanisms the Saxon.NET project has established for providing support. Michael Kay

RE: Error while parsing XQuery - Added by Anonymous about 19 years ago

Legacy ID: #3096029 Legacy Poster: ali (cfsdevln)

hmm... okay, I thought I was missing something really basic that was causing the problem in the saxon-related code and hence wasn't strictly a Saxon.NET problem... Regards, Ali

RE: Error while parsing XQuery - Added by Anonymous about 19 years ago

Legacy ID: #3096152 Legacy Poster: Michael Kay (mhkay)

If you had shown your XQuery code then I would have tried running it on the standard Java product just to see if the problem was common. Actually, looking at it again, I suspect it's caused by Saxon not knowing the base URI of the query. Michael Kay

RE: Error parsing XQuery in Java Saxon - Added by Anonymous about 19 years ago

Legacy ID: #3097635 Legacy Poster: ali (cfsdevln)

I ran it on the standard Java Saxon 8.4 and it gives me the error of a NullPointerException. The stack-trace is the same as i listed in the first post. The query is an example from Stylus Studio and it prints out a multiplication table. Here it is: <table>{ for $y in 1 to 10 return ( <tr>{ for $x in 1 to 10 return let $bg:=(if($x mod 2 + $y mod 2 <= 0) then "lightgreen" else if ($y mod 2 <= 0) then "yellow" else if ($x mod 2 <= 0) then "lightblue" else "white"), $prod:=$x*$y return <td align="right" bgcolor="{$bg}">{ if ($x > 1 and $y > 1) then $prod else <b>{$prod}</b>}</td> }</tr>, " ") }</table>," " Here is the java code: Configuration config = new Configuration(); StaticQueryContext context = new StaticQueryContext(config); //context.setBaseURI("http://example.org"); QueryParser qp = new QueryParser(); qp.parseQuery(query, 0, 0, context); I tried it with setting the BaseURI and declaring it in the query above, still no luck. I must be doing something wrong here as this works fine in Stylus Studio. Thanks, Ali

RE: Debugging it - Added by Anonymous about 19 years ago

Legacy ID: #3097678 Legacy Poster: ali (cfsdevln)

I debugged it and the executable object is null in getLocationMap(). Then I tried context.compileQuery(query) and it worked fine though it uses the QueryParser. I tried parseQuery again after compileQuery but the executable is still null though it isn't null when using compileQuery. As an aside, what i am trying to do here is to parse the xquery so that I can access the xpaths that are used in the query the return values and the individual FLWR expressions etc. I thought that I would use the QueryParser for this. Would this be the correct approach? If not, what would be a better one? Thanks, Ali

RE: Error parsing XQuery in Java Saxon - Added by Anonymous about 19 years ago

Legacy ID: #3097738 Legacy Poster: Michael Kay (mhkay)

Please follow the XQuery API examples shown at http://www.saxonica.com/documentation/using-xquery/embedding.html In particular, use the compileQuery() method on the StaticQueryContext object to compile the query. By invoking the QueryParser directly, you have bypassed some of the initialization. I will try and make some of the methods that are intended for internal use protected, to prevent this kind of thing happening again. Michael Kay http://www.saxonica.com/

    (1-6/6)

    Please register to reply