Project

Profile

Help

Finding xqueries using wrong xpath expression

Added by Anonymous about 15 years ago

Legacy ID: #7050196 Legacy Poster: Sudhir (sudhirdumbre)

hello, I want your suggetion to my problem. i am using xsd and xml confirming that xsd. I have near about 300 xqueries runnng on the xml. Now if any of the attribute name changes or if the element got shifted from one node to another ,xpath gets changed that makes the many of the xqueries invalid (as in they wont be executed as the xpath involved in xquery is changed ) . Till now it is required to visit each and every xquery to check whether that xquery is using correct xpaths or not, if not i need to change xpath and make it running. Is it possible to identify all the xqueries which need to modifiy.is it possible to get list of all xqueries which are no more using correct xpaths. Like if somehow i am able to get all xpaths used in xquery and then validating that xpaths against xpath/xsd ... like that any solution Appreciate your time, thanks.


Replies (3)

Please register to reply

RE: Finding xqueries using wrong xpath expression - Added by Anonymous about 15 years ago

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

A very good question! The best approach is to use schema-aware queries. If you write a query like this: import schema .....; declare variable $doc as document-node(schema-element(my:root)) := .; ... $doc/my:root/a/b/c then there is a very good chance that Saxon will give you a compile time error message if the the path my:root/a/b/c "doesn't make sense", that is, if according to the schema, the path can never select anything. Another approach is to take advantage of the path analysis that Saxon does to support document projection. However, the Saxon interfaces here are fairly primitive, and you would need to do some system programming to take advantage of them. Basically, when you have compiled a query, you can call getPathMap() on the XQueryExpression object, and the path map will tell you which parts of the document are reached by the query. If you know that you have made a change that affects say the path root/a/b/c, then the path map will tell you whether the query makes use of that part of the source document. Yet another approach, which might be the simplest, is to have a regression testing framework, such that you can run through all your queries and see if they still return the same answer as previously. Then you only need to inspect those queries that fail the test.

RE: Finding xqueries using wrong xpath expression - Added by Anonymous almost 15 years ago

Legacy ID: #7473812 Legacy Poster: Sudhir (sudhirdumbre)

Hello Michale, I have downloaded the Saxson SA evaluation version.And put the liciense in classpath but still not able to use the schema aware feature.I am getting the following error .. Error on line 29 column 1 XQST0009: XQuery static error in #...ech :) import schema default#: To import a schema, you need the schema-aware version of Saxon XPathExceptionOne or more static errors were reported during query analysis net.sf.saxon.trans.XPathException: One or more static errors were reported during query analysis at net.sf.saxon.query.QueryParser.parseQuery(QueryParser.java:286) at net.sf.saxon.query.QueryParser.makeXQueryExpression(QueryParser.java:103) at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:338) at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:372) Error on line 29 column 1 XQST0009: XQuery static error in #...ech :) import schema default#: To import a schema, you need the schema-aware version of Saxon net.sf.saxon.trans.XPathException: One or more static errors were reported during query analysis at net.sf.saxon.query.QueryParser.parseQuery(QueryParser.java:286) at net.sf.saxon.query.QueryParser.makeXQueryExpression(QueryParser.java:103) at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:338) at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:372) at com.xquery.FinalQuery.main(FinalQuery.java:44) One or more static errors were reported during query analysis I am using the following import stmt in xquery import schema default element namespace "" at "src/dataset.xsd"; Appreciate your time and Help, thanks.

RE: Finding xqueries using wrong xpath expression - Added by Anonymous almost 15 years ago

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

It's best to start a new thread for a new question - otherwise it becomes very hard for people to find matching questions and answers. It looks as if you are running StaticQueryContext.compileQuery() to compile the query. Presumably you created the SQC earlier using new StaticQueryContext(configuration). You need to ensure that configuration is a SchemaAwareConfiguration not a (plain) Configuration.

    (1-3/3)

    Please register to reply