Project

Profile

Help

NamePool accumulating entries

Added by Anonymous about 16 years ago

Legacy ID: #5440178 Legacy Poster: kendall shaw (queshaw)

If I do a diagnosticDump on the default NamePool used when I use an XPathExpression compiled from XPathEvaluator, I see that it accumulates entries each time I evaluate the expression. To avoid eventually exceeding the namepool limit should I always do (xpe is an XPathExpressionImpl): xpe.getConfiguration.setNamePool(new NamePool()); before evaluating an expression, if I can't predict what namespace declarations there will be? Or, is there a better way to avoid accumulating entries?


Replies (5)

Please register to reply

RE: NamePool accumulating entries - Added by Anonymous about 16 years ago

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

This should not be happening, unless you are doing something rather unusual. Could you please supply a test case that demonstrates the problem?

RE: NamePool accumulating entries - Added by Anonymous about 16 years ago

Legacy ID: #5440444 Legacy Poster: kendall shaw (queshaw)

This is with saxonb 9.1.0.2. /tmp/testa.xml: <?xml version="1.0"?> <doc xmlns="a" xmlns:b="b" b:b="1"/> /tmp/testb.xml: <?xml version="1.0"?> <a:doc xmlns:a="a" xmlns:x="b" x:b="1"/> TestSaxon.java: package test; import java.io.File; import java.io.FileInputStream; import java.io.StringWriter; import javax.xml.transform.Result; import javax.xml.transform.TransformerException; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import net.sf.saxon.Controller; import net.sf.saxon.OutputURIResolver; import net.sf.saxon.TransformerFactoryImpl; import net.sf.saxon.om.NamePool; import net.sf.saxon.xpath.XPathEvaluator; import net.sf.saxon.xpath.XPathExpressionImpl; import org.xml.sax.InputSource; public class TestSaxon { public static void main(String[] args) throws Exception { new TestSaxon().go(); } public void go() throws Exception { final XPathEvaluator xev = new XPathEvaluator(); final XPathExpression xpe = xev.compile("/*[local-name()='doc']"); final File f = new File("/tmp/testa.xml"); final FileInputStream fis = new FileInputStream(f); final InputSource is = new InputSource(fis); final String s = (String) xpe.evaluate(is, XPathConstants.STRING); XPathExpressionImpl xei = (XPathExpressionImpl) xpe; xei.getConfiguration().getNamePool().diagnosticDump(); System.out.println("========================================"); //xei.getConfiguration().setNamePool(new NamePool()); final File f2 = new File("/tmp/testb.xml"); final FileInputStream fis2 = new FileInputStream(f2); final InputSource is2 = new InputSource(fis2); final String s2 = (String) xpe.evaluate(is2, XPathConstants.STRING); xei.getConfiguration().getNamePool().diagnosticDump(); System.out.println("========================================"); xei.getConfiguration().getNamePool().statistics(); } } The second diagnostic dump has an entry for prefix "b" which isn't in testb.xml.

RE: NamePool accumulating entries - Added by Anonymous about 16 years ago

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

The NamePool has grown not because of executing a second query, but because of loading a second XML document containing names that are not present in the first document. The thinking behing the design of the NamePool is that the vast majority of XML applications use a finite (and actually quite small) vocabulary of names, and even if you keep loading new documents, they will typically use the same names as existing documents. Of course, it can take a little while for this process to converge. There are occasional exceptions, for example XML documents that use randomly generated names (or perhaps just randomly generated namespace prefixes) but they are rare. In such cases you may need to think about partitioning the application to use multiple NamePools. I've seen one or two pathological cases of generated documents that bind thousands of namespace prefixes to the same namespace, and I'm afraid Saxon simply cannot handle such documents without preprocessing. Do you actually have a problem with the NamePool growing indefinitely? If so, is there something unusual about the use of names in your XML documents? Michael Kay

RE: NamePool accumulating entries - Added by Anonymous about 16 years ago

Legacy ID: #5442016 Legacy Poster: kendall shaw (queshaw)

Yes, I have some xml that has a ridiculous number of prefixes bound to the same namespace. So, I'm going to do some pre-processing. If I did want to avoid accumulating name pool entries though, can I do that for XSLT, short of recompiling the XSLT for each transformation? If I use XsltCompiler and later set a new namepool like: controller.getConfiguration().setNamePool(new NamePool()); I get an exception about not being able to find something matching a name code. I'm guessing that there are entries for the prefixes in the compiled XSLT that I'm wiping out that way. Can I save a copy of the name pool after the XSLT is compiled and restore it each time to get rid of entries from the document being transformed?

RE: NamePool accumulating entries - Added by Anonymous about 16 years ago

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

You shouldn't change the NamePool for an existing Configuration (perhaps I need to put in a check to prevent it). The purpose of setNamePool() is to allow two Configurations to share the same NamePool, but the method must only be used when initializing the Configuration. You can use multiple Configurations each with its own NamePool, but the rule is that when you run a query or stylesheet, the NamePool used when compiling the query/stylesheet must be the same as the NamePool used at run-time, and the same as the NamePool used for building each of the source documents that participates in the query/stylesheet.

    (1-5/5)

    Please register to reply