Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Exception while parsing XML: org.xml.sax.SAXParseException: Content is not

843834Sep 19 2006 — edited Sep 19 2006
Hi all,

I am trying to run an application which uses XML and Java. It works fine with JRE 1.4.2. but when i try to use it on a machine with java 1.5, it throws the following exception:
here is the trace:


Exception while parsing XML: org.xml.sax.SAXParseException: Content is not allowed in prolog.
org.xml.sax.SAXParseException: Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at webadmin.XmlUtils.readDocumentFromString(XmlUtils.java:76)
at webadmin.XmlUtils.getRootName(XmlUtils.java:188)
at webadmin.messageHandler.procMessageFromServer(messageHandler.java:231)
at webadmin.messageHandler.access$100(messageHandler.java:30)
at webadmin.messageHandler$1.run(messageHandler.java:86)


the code snippet that throws the exception is as follows:

public static Document readDocumentFromString(String xmlData) throws SAXException
{
DocumentBuilderFactory dbf = null;
DocumentBuilder db = null;
org.w3c.dom.Document d = null;

try
{
dbf = DocumentBuilderFactory.newInstance();
// this determines if the parser is a validating parser or not.
// dbf.setValidating(true);
dbf.setValidating(true);
dbf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING,true);

db = dbf.newDocumentBuilder();
db.setErrorHandler(new org.xml.sax.helpers.DefaultHandler());
System.out.println("erroneous Messege:"+xmlData);
d = db.parse(new InputSource(new StringReader(xmlData)));
}
catch(FactoryConfigurationError e)
{
e.printStackTrace();
}
catch (ParserConfigurationException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}

return d;
}

any help would be highly appreciated.

Thanks
Amit
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 17 2006
Added on Sep 19 2006
2 comments
2,345 views