Unknown name code 1724
Added by Anonymous almost 16 years ago
Legacy ID: #6100193 Legacy Poster: sshetty (sshetty123)
Hi, I am writing a simple xquery that will split xml (pagination). Here is the xquery: xquery version "1.0"; declare variable $pageNo as xs:string external; declare variable $pageSize as xs:string external; let $iPageNo := xs:int($pageNo) let $iPageSize := xs:int($pageSize) let $stories := /stories return <stories pageNo="{$pageNo}" pageSize="{$pageSize}"> { for $story at $pos in $stories/story where $pos > $iPageNo * $iPageSize and $pos <= ($iPageNo + 1) * $iPageSize return $story } </stories> Here is the input xml: <stories> <story>this is story 1</story> <story>this is story 2</story> <story>this is story 3</story> <story>this is story 4</story> <story>this is story 5</story> </stories> So far so good. When I run this I see the expected response: <stories pageSize="2" pageNo="0"> <story>this is story 1</story> <story>this is story 2</story> </stories> However, if I add any attributes or child tags to the story tag in the input xml, an IllegalArgument exception ("Unknown name code") is thrown. e.g. <story><para1>this is story 1</para1><para2>this is para 2</para2></story> <story date="1\12\2009">this is story 1</story> Here is the exception stack trace: Caused by: java.lang.IllegalArgumentException: Unknown name code 1724 at net.sf.saxon.om.NamePool.unknownNameCode(NamePool.java:834) at net.sf.saxon.om.NamePool.getDisplayName(NamePool.java:733) at net.sf.saxon.event.XMLEmitter.startElement(XMLEmitter.java:289) at net.sf.saxon.event.XMLIndenter.startElement(XMLIndenter.java:116) at net.sf.saxon.event.NamespaceReducer.startElement(NamespaceReducer.java:72) at net.sf.saxon.event.ComplexContentOutputter.startContent(ComplexContentOutputter.java:529) at net.sf.saxon.tinytree.TinyElementImpl.copy(TinyElementImpl.java:342) at net.sf.saxon.event.ComplexContentOutputter.append(ComplexContentOutputter.java:489) at net.sf.saxon.value.SingletonNode.process(SingletonNode.java:48) at net.sf.saxon.expr.VariableReference.process(VariableReference.java:464) at net.sf.saxon.instruct.Choose.processLeavingTail(Choose.java:688) at net.sf.saxon.instruct.Instruction.process(Instruction.java:93) at net.sf.saxon.expr.ForExpression.process(ForExpression.java:668) at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:551) at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:556) at net.sf.saxon.instruct.Instruction.process(Instruction.java:93) at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:296) at net.sf.saxon.instruct.Instruction.process(Instruction.java:93) at net.sf.saxon.expr.LetExpression.process(LetExpression.java:378) at net.sf.saxon.query.XQueryExpression.run(XQueryExpression.java:394) The xquery works fine in XMLSpy. I see the exception when running via the saxon 9 java api. Any help appreciated. Thanks :) SShetty
Replies (8)
Please register to reply
RE: Unknown name code 1724 - Added by Anonymous almost 16 years ago
Legacy ID: #6102758 Legacy Poster: Michael Kay (mhkay)
The most likely explanation for "Unknown name code" is that there is more than one NamePool in play, and the most likely reason for that if you are using s9api is that there is more than one s9api Processor object. Saxon tries to catch this error but doesn't always succeed.
RE: Unknown name code 1724 - Added by Anonymous almost 16 years ago
Legacy ID: #6102952 Legacy Poster: sshetty (sshetty123)
Thank you Michael. Here is the java code that runs the xquery. Configuration config = new Configuration(); config.setHostLanguage(Configuration.XQUERY); StaticQueryContext sqc = new StaticQueryContext(config); XQueryExpression exp; try { exp = store.getXQuery(xqName); final DynamicQueryContext dynamicContext = new DynamicQueryContext(config); dynamicContext.setContextItem(sqc.buildDocument(inXml)); if (params != null && params.size() > 0) { for (String name : params.keySet()) { dynamicContext.setParameter(name, params.get(name)); } } Result r = new StreamResult(result); exp.run(dynamicContext, r, props); } catch (Exception e) { e.printStackTrace(); throw e; } Is there a workaround for this issue ? How can I find the number of processors being used and how can I limit it to 1 ? Thanks again :) SShetty
RE: Unknown name code 1724 - Added by Anonymous almost 16 years ago
Legacy ID: #6103137 Legacy Poster: Michael Kay (mhkay)
Sorry, I misread your post as saying you were using the s9api interface. I can't see anything obviously wrong with your code. I will have to see if I can reproduce it (when I get home later this week). If you can put together a complete repro (Java code, XML and XQuery source) that will help. Michael Kay
RE: Unknown name code 1724 - Added by Anonymous almost 16 years ago
Legacy ID: #6103888 Legacy Poster: sshetty (sshetty123)
Thank you Michael. Here is the java code that runs the xquery. Configuration config = new Configuration(); config.setHostLanguage(Configuration.XQUERY); StaticQueryContext sqc = new StaticQueryContext(config); XQueryExpression exp; try { exp = store.getXQuery(xqName); final DynamicQueryContext dynamicContext = new DynamicQueryContext(config); dynamicContext.setContextItem(sqc.buildDocument(inXml)); if (params != null && params.size() > 0) { for (String name : params.keySet()) { dynamicContext.setParameter(name, params.get(name)); } } Result r = new StreamResult(result); exp.run(dynamicContext, r, props); } catch (Exception e) { e.printStackTrace(); throw e; } Is there a workaround for this issue ? How can I find the number of processors being used and how can I limit it to 1 ? Thanks again :) SShetty
RE: Unknown name code 1724 - Added by Anonymous almost 16 years ago
Legacy ID: #6124498 Legacy Poster: Michael Kay (mhkay)
A compiled query must be run using the same Configuration as was used to create it. When you do this: exp = store.getXQuery(xqName); you appear to be fetching a compiled query that must have been compiled under a different Configuration, which will therefore be using a different NamePool. Instead of creating a new Configuration when you run the query, use the existing one, which can be accessed as XQueryExpression exp; Configuration config = exp.getExecutable().getConfiguration(); I will add a check to give a cleaner error message in this situation.
RE: Unknown name code 1724 - Added by Anonymous almost 16 years ago
Legacy ID: #6124554 Legacy Poster: Michael Kay (mhkay)
>I will add a check to give a cleaner error message in this situation. In fact that check has already been added in my development version, but it's not there in 9.1
RE: Unknown name code 1724 - Added by Anonymous almost 16 years ago
Legacy ID: #6128382 Legacy Poster: sshetty (sshetty123)
Thank you Michael. That was it. I am using the configuration as you suggested and its working now. Configuration config = exp.getExecutable().getConfiguration(); I just wanted to confirm that the compiled expression exp is thread safe and can be shared across multiple requests/threads ? Thanks again :) SShetty
RE: Unknown name code 1724 - Added by Anonymous almost 16 years ago
Legacy ID: #6128473 Legacy Poster: Michael Kay (mhkay)
Yes, an XQueryExpression is thread-safe - once created, it can be evaluated repeatedly in multiple threads. A Configuration is also designed to be used concurrently in multiple threads, though it's probably a good idea to avoid using any setter methods once it's being shared - i.e. it should ideally have a single-thread setting phase and a multi-thread usage phase.
Please register to reply