OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Re: [Sax-devel] SAX - endDocument() confusion again

[ Lists Home | Date Index | Thread Index ]

At 10:38 AM -0500 2/28/04, Karl Waclawek wrote:

>Good point. However, the docs say this:
>
><quote>
>Note that the locator will return correct information only during 
>the invocation
>SAX event callbacks after startDocument returns and before 
>endDocument is called.
>The application should not attempt to use it at any other time.
></quote>
>Karl


Yes, but the situation is this:

1. Parser opens stream.
2. Parser calls setDocumentLocator and passes in a Locator2.
3. Parser calls startDocument
4. Parser parses XML declaration. Oops there's an error!
5. Parser calls fatalError
6. In fatalError Client calls Locator2.getXMLVersion and/or getEncoding.
7. Parser calls endDocument.

What is the Locator2 supposed to return?

It's to avoid this problem, that Parsifal is not calling either 
setDocumentLocator or startDocument until the declaration (or lack 
thereof) has been successfully parsed.

Possibly, there's a loophole, however The Locator JavaDoc says:

Note that the results returned by the object will be valid only 
during the scope of each callback method: the application will 
receive unpredictable results if it attempts to use the locator at 
any other time, or after parsing completes.

I think it's reasonable to say that parsing was completed before 
fatalError was called; not completed successfully of course, but 
definitely completed. Therefore, there's no place in this chain where 
the Locator methods can be expected to return correct information. 
Therefore Parsifal (and other SAX parsers) should indeed call 
startDocument, fatalError, and endDocument in that order when they 
encounter an error very early in the XML document. If the client uses 
the Locator2 object at any point in this process, they deserve what 
they get.

Possible problem with this chain of reasoning: in more normal 
circumstances it's very useful to use a Locator in fatalError() to 
get the line and column number where the errror appears. This logic 
would forbid such use.

Hmm, still another tricky bit, thisn one not even requiring an error:

1. Parser opens stream.
2. Parser calls setDocumentLocator and passes in a Locator2.
3. Parser calls startDocument. startDocument returns.
4. Another thread uses the Locator2 object before the parser has 
parsed the XML declaration.

What do getXMLVersion and getEncoding return?

I think the best solution is to make a minor fix to the Locator2 
JavaDocs that allow (indeed require) these methods to return null at 
points where the version and encoding are not known.

-- 

   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 




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS