Thursday, December 2, 2010

Jaxp Error ' Content is not allowed in prolog.'

I had the above error when I tried to transform a xml in to another xml.
The mistake was, I have pass the xml file as a ByteArrayInputStream instead of InputStream. I was searching every where about the error but no clue with my code.

            xsltFile = getInputStream(xslPath);
            xmlFile = getInputStream(inputXML);
            Source xmlSource = new StreamSource(xmlFile);
            Source xsltSource = new StreamSource(xsltFile);

            // the factory pattern supports different XSLT processors
            TransformerFactory transFact = TransformerFactory.newInstance();               
            Templates cachedXSLT = transFact.newTemplates(xsltSource);
            Transformer trans = cachedXSLT.newTransformer();

            writer = new StringWriter();
            trans.transform(xmlSource, new StreamResult(writer));


Try to chenge the input type and it would help for you.
Aalso I saw some info in Wrox site.

Sri Lanka - Anyone needs B Positive Blood ?

I have B+ Blood if anyone wants can donate.