Problems in Schema-aware Xquery
Added by Anonymous over 15 years ago
Legacy ID: #7475237 Legacy Poster: Sudhir (sudhirdumbre)
Thank you for ur last reply to thread "Finding Xqueries using wrong xpath". As per our last conversation i have changed the (basic)Configuration to SchemaAwareConfiguration. But still we are not able to track the errors in the XPath expression. For example:Consider the books.xml <Q xsi:noNamespaceSchemaLocation="books.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <BOOKS> <ITEM CAT="MMP"> <TITLE>Pride and Prejudice</TITLE> <AUTHOR>Jane Austen</AUTHOR> <PUBLISHER>Modern Library</PUBLISHER> <PUB-DATE>2002-12-31</PUB-DATE> <LANGUAGE>English</LANGUAGE> <PRICE>4.95</PRICE> <QUANTITY>187</QUANTITY> <ISBN>0679601686</ISBN> <PAGES>352</PAGES> <DIMENSIONS UNIT="in">8.3 5.7 1.1</DIMENSIONS> <WEIGHT UNIT="oz">6.1</WEIGHT> </ITEM> </BOOKS> <CATEGORIES DESC="Miscellaneous categories"> <CATEGORY CODE="P" DESC="Paperback"/> </CATEGORIES> </Q> And the following xquery which just compares the quantity value and pages value. Also note the Xpath for locating the node ITEM is incorrect"//BOOKS/IT".As per my requirement i want to track such errors using schema-aware Saxon. import schema default element namespace "" at "com/xqueries/books.xsd"; for $item in //BOOKS/IT return( if(fn:number($item/QUANTITY) < fn:number($item/PAGES)) then ( <Param>Correct Data</Param> ) else ( <Param>InCorrect Data</Param> ) ) And java code used is as follows: final SchemaAwareConfiguration config = new SchemaAwareConfiguration(); final StaticQueryContext sqc = new StaticQueryContext(config); final XQueryExpression exp = sqc.compileQuery(new FileReader("books.xquery"));
Replies (1)
RE: Problems in Schema-aware Xquery - Added by Anonymous over 15 years ago
Legacy ID: #7475424 Legacy Poster: Michael Kay (mhkay)
Saxon will give you a compile-time warning (not an error, because it isn't an error) if it can determine at compile time that a path expression will select nothing. For this, you have to declare what type of document the query is expected to process. I usually do this by writing: declare variable $input as document-node(schema-element(Q)) := .; for $item in $input//BOOKS/IT .... This also has the effect that you will get a run-time error if you supply the wrong kind of input document, or if the input document has not been validated. Note that in your Java code you should also set config.setSchemaValidation(Validation.STRICT) to ensure that the input document is validated against the schema.
Please register to reply