Hello Rob,

In your original mesage Tuesday, August 12, 2003 11:15 AM you wrote
RO> ...Since I am only interested in Processing Instructions
RO> when I encounter the start element I throw a SAX Exception to abort
RO> parsing:

I am assuming you may have meant to say when you encounter the
Document Element which of course would be the first start element in
the file.
Which also leads me to believe you make the assumption ALL the processing
instructions you are concerned with exist solely in the prolog of the
XML document.
So you are apparently not interested in a processing instruction
that may occur within in an arbitrary position within the xml document
- which is fine if that is what you are trying to do.

I have run 1 meg files through Xerces 2.4.0 and experience no problem
in deleting the file when an exception is thrown during the parsing
process, but I think I may have an idea of where you are running
into the problem:

It depends on where in your application you are attempting to catch
the exception being generated and where you are attempting to delete
the file in question.
    If you are attempting to delete the file within the startElement
    method of the ContentHandler interface(which sounds like what you
    may be doing since you say you "immediately" attempt to delete the
    file) you have not yet returned from the parse method of the
    XMLReader.

    Since you have not yet returned from the parse method (Technically
    the XMLReader may have more reading it needs to perform - so it
    makes sense that it would maintain a reference to the file.

    The SAXException does not indicate the end of parsing but rather
    mereley that there has been an exception generated during the
    parsing.

You may want to try the following:
Surround the parse method call inside of a try block
and catch the exception at this level in your code


    File in = new File("sample.xml");
    String uri = "file:" + in.getAbsolutePath();
    SAXParserFactory   spf = SAXParserFactory.newInstance();
    SAXParser  sp = spf.newSAXParser();
    XMLReader  reader = sp.getXMLReader();
    try {
        reader.parse(uri);
    }
    catch(SAXException e)
    {
        // attempting to delete the file here should be ok
        // and makes sense since at this point parsing is
        // definately complete so the reader no longer maintains
        // a reference to the file in question
        in.delete();
    }
    
Hope this helps
Just makes sense to me not to try to delete the file until the code
has returned from the parse method.

Dave Flanagan



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

Reply via email to