You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Dick Deneer <di...@donkeydevelopment.com> on 2005/12/19 19:19:39 UTC

GrammarPool and property frustration

I can not set the grammar pool on the parser configuration. It says the  
feature is not supported.
But when I try this after the parsing( getting the configuration from  
the document) , then it is allowed.
I don't get the logic of this.  See the output and program at the end  
of this mail.

Also I am getting confused of all the different methods to achieve the  
(same?) goal:
On the page http://xerces.apache.org/xerces2-j/faq-grammars.html   the  
proposed method is:

XMLParserConfiguration config = new XIncludeAwareParserConfiguration();
config.setProperty("http://apache.org/xml/properties/internal/grammar- 
pool",
     myFullGrammarPool);
(SAX|DOM)Parser parser = new (SAX|DOM)Parser(config);

On the page
http://www-128.ibm.com/developerworks/xml/library/x- 
perfap3.html?ca=dnt-535

	
XMLReader parser = XMLReaderFactory.createXMLReader();
try {
     Class poolClass =
         Class.forName("org.apache.xerces.util.XMLGrammarPoolImpl");
     Object grammarPool = poolClass.newInstance();
     parser.setProperty(
         "http://apache.org/xml/properties/internal/grammar-pool",
         grammarPool);
}
catch (Exception e) {}

The property  above (http://xerces.apache.org/xerces2-j/properties.html  
) is in the first example set on the config and in the second example  
set on the parser,
Also this property is not mentioned as JAXP property on page  
http://xerces.apache.org/xerces2-j/properties.html. Does this mean it  
can not be used when using JAXP. And can't you use the JAXP properties  
in the above coding?
SetParamer/setProperty/setFeature/setAttribute, they all do the same,  
but slightly different. I think I really need a matrix to know where to  
set what.

Regards,
Dick Deneer


program output:
Program started
Before parse Canset grammarpool false
Na parse Canset grammarpool true
Program ended
 
Used program:


import java.io.FileInputStream;
import org.apache.xerces.util.XMLGrammarPoolImpl;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.Document;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSParser;

public class TestGrammarPool
{
     public static void main(String[] args) throws Exception
     {
         //give file as input
         System.out.println("Program started");
         System.setProperty(DOMImplementationRegistry.PROPERTY,
                 "org.apache.xerces.dom.DOMXSImplementationSourceImpl");
         DOMImplementationRegistry registry = DOMImplementationRegistry
                 .newInstance();
         DOMImplementationLS impl = (DOMImplementationLS) registry
                 .getDOMImplementation("psvi");
         LSParser parser = impl.createLSParser(
                 DOMImplementationLS.MODE_SYNCHRONOUS, null);
         LSInput in = impl.createLSInput();
         in.setByteStream(new FileInputStream(args[0]));
         DOMConfiguration config = parser.getDomConfig();
         XMLGrammarPoolImpl grammarPool = new XMLGrammarPoolImpl();
         System.out
                 .println("Before parse Canset grammarpool "
                         + config
                                 .canSetParameter(
                                          
"http://apache.org/xml/properties/internal/grammar-pool",
                                         grammarPool));
         Document document = parser.parse(in);
         System.out
                 .println("Na parse Canset grammarpool "
                         + document
                                 .getDomConfig()
                                 .canSetParameter(
                                          
"http://apache.org/xml/properties/internal/grammar-pool",
                                         grammarPool));
         System.out.println("Program ended");
     }
}