You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Thomas <ne...@gmx.net> on 2004/01/09 13:16:54 UTC

Re: SAXException: Document root element is missing [SOLVED]

Hi, again!

Found the error: I need to memoryxml.reset();  before parsing since the 
stream was at the end position.

Now works fine!

Thanks again!

Thomas wrote:

> Thanks Michael!
>
> I created a directory \endorsed in my JRE folder and copied the 
> xercesImpl.jar and xml-apis.jar into that directory.
>
> Now I get the following error:
> SAXException: Premature end of file.
>
> Any ideas?
>
> Best regards,
>
> Tommy
>
>
> Michael Glavassevich wrote:
>
>>Hello Tommy,
>>
>>I've seen this error message before. It doesn't come from Xerces but it
>>does exist in the Crimson message properties. I'm pretty sure you're
>>picking up a version of Crimson from the JDK. With JDK 1.4 adding a
>>version of Xerces to your classpath doesn't override the one which came
>>with the JDK. Have a look at the Endorsed Standards Override Mechanism
>>[1]. It describes how you can override the parser included with the JDK.
>>
>>Hope that helps.
>>
>>[1] http://java.sun.com/j2se/1.4.1/docs/guide/standards/
>>
>>On Thu, 8 Jan 2004, Thomas wrote:
>>
>>  
>>
>>>Hello!
>>>
>>>I have written the following small method to check if a memory xml
>>>stream is well-formed:
>>>
>>>    public void parse(ByteArrayInputStream memoryxml) {
>>>        try {
>>>            InputSource input = new InputSource(memoryxml);
>>>            input.setEncoding("utf-8");
>>>            input.setByteStream(memoryxml);
>>>
>>>            DocumentBuilderFactory factory =
>>>DocumentBuilderFactory.newInstance();
>>>            factory.setValidating(false);
>>>
>>>            DocumentBuilder parser = factory.newDocumentBuilder();
>>>
>>>            Document document = parser.parse(input);
>>>
>>>        } catch (SAXException sex) {
>>>            logger.error("SAXException: " + sex.getMessage());
>>>        } catch (IOException iox) {
>>>            logger.error("IOException: " + iox.getMessage());
>>>        } catch (ParserConfigurationException pcex) {
>>>            logger.error("ParserConfigException:" + pcex.getMessage());
>>>        }
>>>        logger.info("FINISH!");
>>>    }
>>>
>>>Unfortunately, it always returns  SAXException: Document root element is
>>>missing.
>>>I am pretty sure the memoryxml contains valid xml data with a document root.
>>>I use JDK 1.4.1 and Eclipse 3.0M4.
>>>
>>>It works fine when I pass a File instead of the memory stream...
>>>
>>>Best regards,
>>>
>>>Tommy
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>>>For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>>>    
>>>
>>
>>---------------------------
>>Michael Glavassevich
>>XML Parser Development
>>IBM Toronto Lab
>>E-mail: mrglavas@ca.ibm.com
>>E-mail: mrglavas@apache.org
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>>For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>>
>>
>>  
>>
>