Entity references not correctly resolved when DTD is cached
-----------------------------------------------------------
Key: XERCESJ-1465
URL: https://issues.apache.org/jira/browse/XERCESJ-1465
Project: Xerces2-J
Issue Type: Bug
Components: XNI
Affects Versions: 2.10.0
Environment: java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02-279-10M3065)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01-279, mixed mode)
Reporter: Thomas Krammer
When using a XMLGrammarCachingConfiguration to cache the parsed DTD entity
references are no longer correctly resolved.
The following example:
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.IOException;
import java.io.StringReader;
public class XercesCachingTest
{
public static final String XHTML_1_0_DOCTYPE = "<!DOCTYPE html PUBLIC
\"-//W3C//DTD XHTML 1.0 Strict//EN\" " +
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
public static void main(String[] args) throws Exception
{
System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration",
"org.apache.xerces.parsers.XMLGrammarCachingConfiguration");
final SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
final SAXParser parser = factory.newSAXParser();
for(int i=0 ; i< 3 ; i++) {
parse(parser);
}
}
private static void parse(SAXParser parser)
throws SAXException, IOException
{
final XMLReader reader = parser.getXMLReader();
reader.setEntityResolver(new EntityResolver()
{
@Override
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException
{
return new InputSource(new StringReader("<!ENTITY nbsp
\" \">"));
}
});
reader.setContentHandler(new DefaultHandler()
{
@Override
public void characters(char[] ch, int start, int length) throws
SAXException
{
System.out.print(new String(ch, start, length));
}
});
reader.parse(new InputSource(new
StringReader(XHTML_1_0_DOCTYPE+"<html><body>Hello world</body></html>")));
System.out.println("");
parser.reset();
}
}
prints "Hello world" for the first parser invocation, "Helloworld" for all
following invocations.
When I remove the System.setProperty(...) line everything works correctly.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]