At 12:56 PM +1000 3/4/04, Peter B. West wrote:
Fops,

In HEAD, ///apps/FOFileHAndler.java contains the following:

    protected static XMLReader createParser() throws FOPException {
        try {
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setFeature(
                "http://xml.org/sax/features/namespace-prefixes";, true);
            return factory.newSAXParser().getXMLReader();
        } catch (SAXNotSupportedException se) {
            throw new FOPException("Error: You need a parser which allows the"
                   + " http://xml.org/sax/features/namespace-prefixes";
                   + " feature to be set to true to support namespaces", se);


I would be inclined to modify that to:


    protected static XMLReader createParser() throws FOPException {
        try {
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setNamespaceAware(true);
            return factory.newSAXParser().getXMLReader();
        } catch (SAXNotSupportedException se) {
            throw new FOPException("Error: You need a parser which allows the"
                   + " http://xml.org/sax/features/namespaces";
                   + " feature to be set to true to support namespaces", se);


What I ask on reading this code is why you're using SAXParserFactory at all? SAXParserFactory is a Sun class they invented to fill a hole in SAX 1.0. It's unnecessary in SAX 2.0. SAX2 apps should use XMLReaderFactory instead, which has the correct defaults you want in the first place. It would look something like this:


   protected static XMLReader createParser() throws FOPException {
        try {
            XMLReader parser = XMLReaderFactory.createXMLReader();
            return parser;
        } catch (SAXException se) {
            throw new FOPException("Could not find a parser. Make sure the"
            + "???? system property is set");
        }
  }

That's off the top of my head so it may not compile, and there are ways to look for alternative parsers if you don't find one immediately (See http://www.cafeconleche.org/books/xmljava/chapters/ch07.html#d0e9994 ) but you get the idea.

--

Elliotte Rusty Harold
[EMAIL PROTECTED]
Effective XML (Addison-Wesley, 2003)
http://www.cafeconleche.org/books/effectivexml http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA

Reply via email to