org.xml.sax.SAXParseException: Invalid encoding name "HP-ROMAN8"

Alex Geller <[email protected]>
Newsgroups gmane.text.xml.batik.user
Message-ID <[email protected]>
Hi,
I am not sure if this is a Batik only issue but since I encountered it using
Batik I will share the problem and the solution I have found so far.

Description of the problem:
If you have a program that reads XML files and you add "xerces_2_5_0.jar" to
your CLASSPATH on a HP-UX machine (or any other machine that has proprietary
XML encodings) then the program may fail with the exception
"org.xml.sax.SAXParseException: Invalid encoding name "HP-ROMAN8"".

Note that the existence of this jar in the CLASSPATH is sufficient to make
this happen. The following test program illustrates the issue (forgive the
deprecation warning):

import org.xml.sax.InputSource;
import javax.xml.parsers.SAXParserFactory;
import java.io.StringBufferInputStream;
public class EncodingTest
{
    public static void main(String[] args) throws Exception
    {
       
SAXParserFactory.newInstance().newSAXParser().getXMLReader().parse(new
InputSource(new StringBufferInputStream("<?xml version=\"1.0\"
encoding=\"HP-ROMAN8\"?> ")));
    }
}

Consider the following invocations:
Example 1:
$(unset CLASSPATH;java -Djaxp.debug=1 EncodingTest)
JAXP: find factoryId =javax.xml.parsers.SAXParserFactory
JAXP: loaded from fallback value:
com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
JAXP: created new instance of class
com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using
ClassLoader: null
$

Example 2:
$(export CLASSPATH=.:$BATIKDIR/batik-1.7/lib/xerces_2_5_0.jar;java
-Djaxp.debug=1 EncodingTest)
JAXP: find factoryId =javax.xml.parsers.SAXParserFactory
JAXP: found jar
resource=META-INF/services/javax.xml.parsers.SAXParserFactory using
ClassLoader: sun.misc.Launcher$AppClassLoader@df6ccd
JAXP: found in resource, value=org.apache.xerces.jaxp.SAXParserFactoryImpl
JAXP: created new instance of class
org.apache.xerces.jaxp.SAXParserFactoryImpl using ClassLoader:
sun.misc.Launcher$AppClassLoader@df6ccd
[Fatal Error] :1:43: Invalid encoding name "HP-ROMAN8".
Exception in thread "main" org.xml.sax.SAXParseException: Invalid encoding
name "HP-ROMAN8".
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at EncodingTest.main(EncodingTest.java:9)
$

Now, the issue can be fixed by forcing the JVM to use the default factory by
settings the property javax.xml.parsers.SAXParserFactory as described in
http://docs.oracle.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory.html#newInstance()
as follows:

Example 3:

$(export CLASSPATH=.:$BATIKDIR/batik-1.7/lib/xerces_2_5_0.jar;java
-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
-Djaxp.debug=1 EncodingTest)
JAXP: find factoryId =javax.xml.parsers.SAXParserFactory
JAXP: found system property,
value=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
JAXP: created new instance of class
com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using
ClassLoader: null
$

Questions:
1) Is it necessary to include xerces_2_5_0.jar in the CLASSPATH?
2) If yes, how can I load documents with local encodings and use Batik at
the same time.

Thanks,
Alex 

~   

--
View this message in context: http://batik.2283329.n4.nabble.com/org-xml-sax-SAXParseException-Invalid-encoding-name-HP-ROMAN8-tp4103307p4103307.html
Sent from the Batik - Users mailing list archive at Nabble.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.