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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to