Hi Raj,

Thanks for catching this problem. I've applied a fix to CVS, one somewhat 
different than what you suggested. EntityResolver2 isn't supported in 
Xerces 2.6.2 (the most recent release) nor will you find it in the latest 
CVS code. We plan to move up to SAX 2.0.2 which includes EntityResolver2 
in Xerces 2.7.0 (still in development).

Thanks.

Ritu Raj Tiwari <[EMAIL PROTECTED]> wrote on 02/24/2005 12:58:09 
PM:

> Hi Michael,
> I am using the xerces implementation bundled with
> JDK5.0. Like I mentioned earlier, when a document w/o
> a doctype is encountered, the following method is
> called on my entity resolver: 
> public InputSource getExternalSubset( String name,
> String baseURI )
> 
> I stepped through my debugger after this point and I
> end up in
> XMLDocumentScannerImpl.resolveExternalSubsetAndRead()
> 
> This method gets the public and system id from my
> entity resolver and inserts a fake DTD declaration by
> calling:
> fDocumentHandler.doctypeDecl(fDoctypeName,
> fDoctypePublicId, fDoctypeSystemId, null);
> 
> This insertion seems to do the right thing. I follow
> the above method into XMLDTDValidator.doctypeDecl()
> and see the following happen:
> fGrammarBucket.setActiveGrammar(fDTDGrammar);
> where fDTDGrammar is from the pool
> 
> Coming back into
> XMLDocumentScannerImpl.resolveExternalSubsetAndRead()
> I find things going wrong. Here is the bothering
> segment of code:
> 
> // (Raj) This part makes sense - inserting a doctype
> // declaration
> // call document handler
> if (fDocumentHandler != null) {
> // This inserts a doctypeDecl event into the stream
> though no 
> // DOCTYPE existed in the instance document.
>   fDocumentHandler.doctypeDecl(fDoctypeName,
> fDoctypePublicId, fDoctypeSystemId, null);
> }
> // (Raj) This part does not make sense if grammar has
> already been found in pool
> try {
>   fDTDScanner.setInputSource(src);
>   while (fDTDScanner.scanDTDExternalSubset(true));
> }
> .
> .
> .
> 
> Would you recommend moving to the latest stable xerces
> rather than the one packaged with the JDK?
> 
> Thanks.
> -Raj
> --- Michael Glavassevich <[EMAIL PROTECTED]> wrote:
> 
> > Hello Raj,
> > 
> > The grammar pool is only consulted when the document
> > has a DTD. Documents 
> > without a DOCTYPE don't have one. If you've
> > registered an instance of 
> > EntityResolver2 with the parser it will call
> > getExternalSubset() to give 
> > your application an opportunity to provide a DTD,
> > effectively inserting a 
> > DOCTYPE declaration before the root element with the
> > sequence of SAX 
> > events your application would receive if there was a
> > DOCTYPE present. If 
> > you return an InputSource containing external
> > identifiers (public id 
> > and/or system id) the parser will check if the
> > grammar pool already has 
> > the DTD, otherwise it will attempt to read from the
> > InputStream or Reader. 
> > At least this is what the version of Xerces in CVS
> > will do. There haven't 
> > been any releases which support EntityResolver2 yet
> > so you must be using 
> > some derivative of the Apache code.
> > 
> > Ritu Raj Tiwari <[EMAIL PROTECTED]> wrote on
> > 02/23/2005 04:37:49 
> > PM:
> > 
> > > >Am I missing something here? If the document has
> > no
> > > > DOCTYPE declaration there's no DTD to load.
> > > 
> > > Before using the XMLReader, I set my own
> > > EntitResolver2 implementation as the XMLReader's
> > > entityResolver. On running in a debugger, For
> > > documents that *do* bear a DOCTYPE declaration, I
> > see
> > > the following method on my entityResolver getting
> > > invoked:
> > > public InputSource resolveEntity( String name,
> > String
> > > publicId, String baseURI, String systemId )
> > > 
> > > This method is getting invoked only *once* when
> > the
> > > first document is encountered. It is not invoked
> > for
> > > any future documents, so I can see that the
> > caching
> > > works. (If I don't configure the parser with a
> > grammar
> > > pool, this method is called over and over for each
> > new
> > > XML document).
> > > 
> > > For documents that don't have a DOCTYPE, the
> > following
> > > entityResolver method is called: 
> > > public InputSource getExternalSubset( String name,
> > > String baseURI )
> > > 
> > > This gets called over and over, despite a matching
> > > grammar being found in the pool. I know that
> > because I
> > > pre-populate the pool with a grammar that has an
> > empty
> > > XMLGrammarDescription ("::::"). Breakpointing on
> > >
> > XMLGrammarPoolImpl.getGrammar(XMLGrammarDescription
> > > desc) shows this grammar being returned for
> > documents
> > > without DOCTYPE...and yet, I see the DTD being
> > > scanned.
> > > 
> > > Does this make sense? I'd be happy to provide any
> > more
> > > information.
> > > 
> > > Thanks for your responses.
> > > -Raj
> > > 
> > > 
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > > 
> > 
> > Michael Glavassevich
> > XML Parser Development
> > IBM Toronto Lab
> > E-mail: [EMAIL PROTECTED]
> > E-mail: [EMAIL PROTECTED]
> > 
> > 
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to