You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "Peter B. West" <pb...@powerup.com.au> on 2004/03/04 03:56:28 UTC

namespace-prefixes

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);


That is, I would turn allow the namespace-prefixes feature to remain in 
its default 'false' state, but make sure the parser is namespace aware. 
  I don't know that there is any reason for us to collect prefixes, 
rather than simply allowing the parser to keep track of the namespaces 
in effect and return namespace and local names.  That's what I have done 
in alt-design without any regrets so far.

Peter
-- 
Peter B. West <http://www.powerup.com.au/~pbwest/resume.html>


Re: namespace-prefixes

Posted by Clay Leeds <cl...@medata.com>.
On Mar 4, 2004, at 6:53 PM, Elliotte Rusty Harold wrote:
> At 10:43 AM +1000 3/5/04, Peter B. West wrote:
>
>> I think this might be because the HEAD developers were moving to a 
>> JAXP implementation, and SAXParserFactory is still in the 1.4 
>> javax.xml.parsers package, which, AIUI, is what one is supposed to 
>> use for JAXP-compatible applications.  I don't know much about JAXP, 
>> so this could be wrong.
>
> It's a common misconception, but it is very much a misconception.  I 
> don't know how this meme got started, but it is annoyingly persistent; 
> and it causes people all sorts of trouble. SAXParserFactory should not 
> be used in 2004. It does not replace XMLReaderFactory. In fact, the 
> opposite is true. XMLReaderFactory replaces SAXParserFactory.  The 
> only reason SAXParserFactory exists is to support SAX 1.0. It is 
> underspecified and has completely wrong defaults for handling 
> namespaces or SAX 2.
>
> Honestly Sun should never have released it in the first place. By the 
> time they released JAXP 1.0, SAX 2.0 was in late beta, just weeks from 
> release, and was obviously going to render JAXP 1.0 obsolete; but Sun 
> went ahead anyway, and thoroughly confused the market. Not invented 
> here syndrome, I think.  They simply were not willing to accept a 
> process they didn't control.  Four years later the rest of us are 
> still paying the price for their hubris. :-(
> -- 
>
>   Elliotte Rusty Harold

Two questions regarding this (forgive my naivete!):
- does a switch from SAXParserFactory to XMLReaderFactory have any 
bearing on the discussion about whether FOP should change its minimum 
JRE from 1.3/1.2 to 1.4?
- if XMLReaderFactory works under JDK 1.3 and/or 1.2, what kinds of 
benefits might fop-0.20.5 see from a switch to XMLReaderFactory?

Web Maestro Clay
-- 
Clay Leeds - cleeds@medata.com
Web Developer - Medata, Inc. - <http://www.medata.com/>
PGP Public Key: <https://mail.medata.com/pgp/cleeds.asc>


Re: namespace-prefixes

Posted by Elliotte Rusty Harold <el...@metalab.unc.edu>.
At 9:07 PM -0800 3/4/04, Clay Leeds wrote:
>On Mar 4, 2004, at 6:53 PM, Elliotte Rusty Harold wrote:
>>  At 10:43 AM +1000 3/5/04, Peter B. West wrote:
>>
>>>  I think this might be because the HEAD developers were moving to 
>>>a JAXP implementation, and SAXParserFactory is still in the 1.4 
>>>javax.xml.parsers package, which, AIUI, is what one is supposed to 
>>>use for JAXP-compatible applications.  I don't know much about 
>>>JAXP, so this could be wrong.
>>
>>  It's a common misconception, but it is very much a misconception. 
>>I don't know how this meme got started, but it is annoyingly 
>>persistent; and it causes people all sorts of trouble. 
>>SAXParserFactory should not be used in 2004. It does not replace 
>>XMLReaderFactory. In fact, the opposite is true. XMLReaderFactory 
>>replaces SAXParserFactory.  The only reason SAXParserFactory exists 
>>is to support SAX 1.0. It is underspecified and has completely 
>>wrong defaults for handling namespaces or SAX 2.
>>
>>  Honestly Sun should never have released it in the first place. By 
>>the time they released JAXP 1.0, SAX 2.0 was in late beta, just 
>>weeks from release, and was obviously going to render JAXP 1.0 
>>obsolete; but Sun went ahead anyway, and thoroughly confused the 
>>market. Not invented here syndrome, I think.  They simply were not 
>>willing to accept a process they didn't control.  Four years later 
>>the rest of us are still paying the price for their hubris. :-(
>>  --
>>    Elliotte Rusty Harold
>
>Two questions regarding this (forgive my naivete!):
>- does a switch from SAXParserFactory to XMLReaderFactory have any 
>bearing on the discussion about whether FOP should change its 
>minimum JRE from 1.3/1.2 to 1.4?

None. XMLReaderFactory works with any compliant SAX 2 parser.

>- if XMLReaderFactory works under JDK 1.3 and/or 1.2, what kinds of 
>benefits might fop-0.20.5 see from a switch to XMLReaderFactory?

Cleaner simpler code that's less likely to get hosed by different 
implementations interpreting a spec in very different ways.  Plus 
you'll be ready for the eventual deprecation of SAXParserFactory in 
JAXP 1.4. And you'll be able to work with SAX parsers that don't 
support JAXP. Not sure how much of an issue that is any more in 
practice, but it was a very real issue in the recent past.
-- 

   Elliotte Rusty Harold
   elharo@metalab.unc.edu
   Effective XML (Addison-Wesley, 2003)
   http://www.cafeconleche.org/books/effectivexml
   http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA

Re: namespace-prefixes

Posted by Clay Leeds <cl...@medata.com>.
On Mar 4, 2004, at 6:53 PM, Elliotte Rusty Harold wrote:
> At 10:43 AM +1000 3/5/04, Peter B. West wrote:
>
>> I think this might be because the HEAD developers were moving to a 
>> JAXP implementation, and SAXParserFactory is still in the 1.4 
>> javax.xml.parsers package, which, AIUI, is what one is supposed to 
>> use for JAXP-compatible applications.  I don't know much about JAXP, 
>> so this could be wrong.
>
> It's a common misconception, but it is very much a misconception.  I 
> don't know how this meme got started, but it is annoyingly persistent; 
> and it causes people all sorts of trouble. SAXParserFactory should not 
> be used in 2004. It does not replace XMLReaderFactory. In fact, the 
> opposite is true. XMLReaderFactory replaces SAXParserFactory.  The 
> only reason SAXParserFactory exists is to support SAX 1.0. It is 
> underspecified and has completely wrong defaults for handling 
> namespaces or SAX 2.
>
> Honestly Sun should never have released it in the first place. By the 
> time they released JAXP 1.0, SAX 2.0 was in late beta, just weeks from 
> release, and was obviously going to render JAXP 1.0 obsolete; but Sun 
> went ahead anyway, and thoroughly confused the market. Not invented 
> here syndrome, I think.  They simply were not willing to accept a 
> process they didn't control.  Four years later the rest of us are 
> still paying the price for their hubris. :-(
> -- 
>
>   Elliotte Rusty Harold

Two questions regarding this (forgive my naivete!):
- does a switch from SAXParserFactory to XMLReaderFactory have any 
bearing on the discussion about whether FOP should change its minimum 
JRE from 1.3/1.2 to 1.4?
- if XMLReaderFactory works under JDK 1.3 and/or 1.2, what kinds of 
benefits might fop-0.20.5 see from a switch to XMLReaderFactory?


Re: namespace-prefixes

Posted by Elliotte Rusty Harold <el...@metalab.unc.edu>.
At 10:43 AM +1000 3/5/04, Peter B. West wrote:

>I think this might be because the HEAD developers were moving to a 
>JAXP implementation, and SAXParserFactory is still in the 1.4 
>javax.xml.parsers package, which, AIUI, is what one is supposed to 
>use for JAXP-compatible applications.  I don't know much about JAXP, 
>so this could be wrong.

It's a common misconception, but it is very much a misconception.  I 
don't know how this meme got started, but it is annoyingly 
persistent; and it causes people all sorts of trouble. 
SAXParserFactory should not be used in 2004. It does not replace 
XMLReaderFactory. In fact, the opposite is true. XMLReaderFactory 
replaces SAXParserFactory.  The only reason SAXParserFactory exists 
is to support SAX 1.0. It is underspecified and has completely wrong 
defaults for handling namespaces or SAX 2.

Honestly Sun should never have released it in the first place. By the 
time they released JAXP 1.0, SAX 2.0 was in late beta, just weeks 
from release, and was obviously going to render JAXP 1.0 obsolete; 
but Sun went ahead anyway, and thoroughly confused the market. Not 
invented here syndrome, I think.  They simply were not willing to 
accept a process they didn't control.  Four years later the rest of 
us are still paying the price for their hubris. :-(
-- 

   Elliotte Rusty Harold
   elharo@metalab.unc.edu
   Effective XML (Addison-Wesley, 2003)
   http://www.cafeconleche.org/books/effectivexml
   http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA

Re: namespace-prefixes

Posted by "Peter B. West" <pb...@powerup.com.au>.
Elliotte Rusty Harold wrote:
> At 12:56 PM +1000 3/4/04, Peter B. West wrote:
> 
...
>>             SAXParserFactory factory = SAXParserFactory.newInstance();
>>             factory.setNamespaceAware(true);
>>             return factory.newSAXParser().getXMLReader();
>>
...
> 
> 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,

I think this might be because the HEAD developers were moving to a JAXP 
implementation, and SAXParserFactory is still in the 1.4 
javax.xml.parsers package, which, AIUI, is what one is supposed to use 
for JAXP-compatible applications.  I don't know much about JAXP, so this 
could be wrong.

Peter
-- 
Peter B. West <http://www.powerup.com.au/~pbwest/resume.html>


Re: namespace-prefixes

Posted by Elliotte Rusty Harold <el...@metalab.unc.edu>.
At 2:36 PM -0800 3/4/04, Glen Mazza wrote:
>--- Elliotte Rusty Harold <el...@metalab.unc.edu>
>wrote:
>>  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:
>>
>
>Mr. Harold,
>
>Pardon my ignorance here--but do the Xalan libraries
>that ship with the 1.4 JDK handle SAX 2.0?

Yes, they absolutely do. If you're using namespaces, XMLReader, 
ContentHandler, and so forth (and you really have to be for XSL) then 
you are already using SAX 2.

>  The Xalan
>home page [1] is ambiguous on their support of it, and
>I'm concerned if there would be compatability problems
>if we were to use it.

I'm not quite sure what you're seeing on that page that concerns you, 
but I don't see anything there that should prevent you from using 
XMLReaderFactory.
-- 

   Elliotte Rusty Harold
   elharo@metalab.unc.edu
   Effective XML (Addison-Wesley, 2003)
   http://www.cafeconleche.org/books/effectivexml
   http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA

Re: namespace-prefixes

Posted by Glen Mazza <gr...@yahoo.com>.
--- Elliotte Rusty Harold <el...@metalab.unc.edu>
wrote:
> 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:
> 

Mr. Harold,

Pardon my ignorance here--but do the Xalan libraries
that ship with the 1.4 JDK handle SAX 2.0?  The Xalan
home page [1] is ambiguous on their support of it, and
I'm concerned if there would be compatability problems
if we were to use it.

Thanks,
Glen

[1] http://xml.apache.org/xalan-j/index.html

Re: namespace-prefixes

Posted by Elliotte Rusty Harold <el...@metalab.unc.edu>.
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
   elharo@metalab.unc.edu
   Effective XML (Addison-Wesley, 2003)
   http://www.cafeconleche.org/books/effectivexml            
   http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA 

Re: namespace-prefixes

Posted by "Peter B. West" <pb...@powerup.com.au>.
Glen Mazza wrote:
> --- "Peter B. West" <pb...@powerup.com.au> wrote:
> 
...

>>That is, I would turn allow the namespace-prefixes
>>feature to remain in 
>>its default 'false' state, but make sure the parser
>>is namespace aware. 
>>  I don't know that there is any reason for us to
>>collect prefixes, 
> 
> 
> This is somewhat outside my knowledge, but one
> difference, I believe, between HEAD and Alt-Design is
> the former's ability to have user-configured, run-time
> add-in element mappings.  (I think we have one for
> MathML and another one for something else in our
> examples.)  Given that, could that be HEAD's reason
> for needing to collect prefixes?

I don't think so.  Prefixes are a shorthand convenience - they must be 
supported by underlying full namespaces.  Prefixes are unstable, in that 
the same3 prefix can signify completely different namespaces at 
different points in the file, IIUC.

Peter
-- 
Peter B. West <http://www.powerup.com.au/~pbwest/resume.html>


Re: namespace-prefixes

Posted by Glen Mazza <gr...@yahoo.com>.
--- "Peter B. West" <pb...@powerup.com.au> wrote:
> In HEAD, ///apps/FOFileHAndler.java contains the
> following:
> 
>              factory.setFeature(
>                 
> "http://xml.org/sax/features/namespace-prefixes",
> true);

<snip/>

> That is, I would turn allow the namespace-prefixes
> feature to remain in 
> its default 'false' state, but make sure the parser
> is namespace aware. 
>   I don't know that there is any reason for us to
> collect prefixes, 

This is somewhat outside my knowledge, but one
difference, I believe, between HEAD and Alt-Design is
the former's ability to have user-configured, run-time
add-in element mappings.  (I think we have one for
MathML and another one for something else in our
examples.)  Given that, could that be HEAD's reason
for needing to collect prefixes?

Glen