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 2006/10/19 14:42:17 UTC

Why can 't I set a grammarPool on LSParser

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
				.println("Read cansetParamater http://apache.org/xml/properties/ 
internal/grammar-pool "
						+ config
								.canSetParameter(
										"http://apache.org/xml/properties/internal/grammar-pool",
										new XMLGrammarPoolImpl()));
		config.setParameter(
				"http://apache.org/xml/properties/internal/grammar-pool",
				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 = org.apache.xerces.parsers.DOMParserImpl@329f3d
Read cansetParamater http://apache.org/xml/properties/internal/ 
grammar-pool false
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)











Re: Why can 't I set a grammarPool on LSParser

Posted by Dick Deneer <di...@donkeydevelopment.com>.
I also noticed that in the DOM revalidation (NormalizeDoucument())  
you can set this property, but DTD's are not added to the  
grammarpool; fotunatelly: if there is a appropriate DTD present in  
the pool, it will be used.

Op 19-okt-2006, om 14:42 heeft Dick Deneer het volgende geschreven:

> 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
> 				.println("Read cansetParamater http://apache.org/xml/properties/ 
> internal/grammar-pool "
> 						+ config
> 								.canSetParameter(
> 										"http://apache.org/xml/properties/internal/grammar-pool",
> 										new XMLGrammarPoolImpl()));
> 		config.setParameter(
> 				"http://apache.org/xml/properties/internal/grammar-pool",
> 				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 = org.apache.xerces.parsers.DOMParserImpl@329f3d
> Read cansetParamater http://apache.org/xml/properties/internal/ 
> grammar-pool false
> 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)
>
>
>
>
>
>
>
>
>
>