I wonder why I may not  use a grammarPool on the LSParser:

Code:
import org.apache.xerces.util.XMLGrammarPoolImpl;
import org.w3c.dom.DOMError;
import org.w3c.dom.DOMErrorHandler;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSParser;

/*
* @version 1.5 2005-10-20 by DD Changed setDocument in method read
* @version 1.6 Register GrammarPool
*/
public class DOMParser implements DOMErrorHandler
{
DOMImplementationLS impl = null;

LSParser parser = null;

public DOMParser()
{

System.setProperty(DOMImplementationRegistry.PROPERTY,
"org.apache.xerces.dom.DOMXSImplementationSourceImpl");

DOMImplementationRegistry registry = null;
try
{
registry = DOMImplementationRegistry.newInstance();
}
catch (ClassCastException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (InstantiationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

impl = (DOMImplementationLS) registry.getDOMImplementation("psvi");

parser = impl
.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

}

// first read from file
public void read(String fileName) throws Exception
{

org.w3c.dom.DOMConfiguration config = parser.getDomConfig();
System.out.println("Configuration class = " + config);
config.setParameter("datatype-normalization", Boolean.FALSE);
config.setParameter("error-handler", this);
config.setParameter("validate", Boolean.FALSE);
config.setParameter("psvi", Boolean.TRUE);

// je kunt geen grammarPool gebruiken hier
System.out
+ config
.canSetParameter(
new XMLGrammarPoolImpl()));
config.setParameter(
new XMLGrammarPoolImpl());
config.setParameter("error-handler", this);

// if you want to keep cdata
config.setParameter("cdata-sections", Boolean.TRUE);

parser.parseURI(fileName);

}

public boolean handleError(DOMError arg0)
{
// TODO Auto-generated method stub
System.out.println(arg0);
return false;
}

public static void main(String[] args)
{
DOMParser parser = new DOMParser();
try
{
parser.read("xml/po.xml");
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

Output:
Configuration class = [EMAIL PROTECTED]
org.w3c.dom.DOMException: FEATURE_NOT_FOUND: The parameter http://apache.org/xml/properties/internal/grammar-pool is not recognized.
at org.apache.xerces.parsers.DOMParserImpl.setParameter(Unknown Source)
at DOMParser.read(DOMParser.java:81)
at DOMParser.main(DOMParser.java:105)










Reply via email to