M
moralbarometer
Please i intend to make an XML document from a string using tranformer
as shown below. It returns an error which trace is given below as well.
please help.
public org.w3c.dom.Node getTextXML() {
try
{
javax.xml.transform.dom.DOMResult domresult=new
javax.xml.transform.dom.DOMResult();
StringReader textReader=new StringReader("<a>testing</a>");
xmlin=new javax.xml.transform.stream.StreamSource(textReader);
TransformerFactory tfl=TransformerFactory.newInstance();
Transformer trl=tfl.newTransformer();
trl.transform (xmlin,domresult);
return domresult.getNode();
}
catch(Exception e)
{
e.printStackTrace (System.out);
}
finally
{
}
return null;
}
javax.xml.transform.TransformerException:
org.xml.sax.SAXParseException: Content is not allowed in prolog.
at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:501)
at Info.Mailer.getTextXML(Mailer.java:516)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction(ExtensionHandlerJavaClass.java:399)
at
org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction(ExtensionHandlerJavaClass.java:438)
at
org.apache.xalan.extensions.ExtensionsTable.extFunction(ExtensionsTable.java:220)
at
org.apache.xalan.transformer.TransformerImpl.extFunction(TransformerImpl.java:473)
at
org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:206)
at org.apache.xpath.XPath.execute(XPath.java:335)
at
org.apache.xalan.templates.ElemCopyOf.execute(ElemCopyOf.java:132)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2281)
at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1367)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1284)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1262)
at Info.Mailer.sendmail(Mailer.java:153)
at Info.Mailer.main(Mailer.java:27)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in
prolog.
at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
at
org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
Source)
at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
... 28 more
---------
org.xml.sax.SAXParseException: Content is not allowed in prolog.
at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
at
org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
Source)
at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
at Info.Mailer.getTextXML(Mailer.java:516)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction(ExtensionHandlerJavaClass.java:399)
at
org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction(ExtensionHandlerJavaClass.java:438)
at
org.apache.xalan.extensions.ExtensionsTable.extFunction(ExtensionsTable.java:220)
at
org.apache.xalan.transformer.TransformerImpl.extFunction(TransformerImpl.java:473)
at
org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:206)
at org.apache.xpath.XPath.execute(XPath.java:335)
at
org.apache.xalan.templates.ElemCopyOf.execute(ElemCopyOf.java:132)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2281)
at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1367)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1284)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1262)
at Info.Mailer.sendmail(Mailer.java:153)
at Info.Mailer.main(Mailer.java:27)
as shown below. It returns an error which trace is given below as well.
please help.
public org.w3c.dom.Node getTextXML() {
try
{
javax.xml.transform.dom.DOMResult domresult=new
javax.xml.transform.dom.DOMResult();
StringReader textReader=new StringReader("<a>testing</a>");
xmlin=new javax.xml.transform.stream.StreamSource(textReader);
TransformerFactory tfl=TransformerFactory.newInstance();
Transformer trl=tfl.newTransformer();
trl.transform (xmlin,domresult);
return domresult.getNode();
}
catch(Exception e)
{
e.printStackTrace (System.out);
}
finally
{
}
return null;
}
javax.xml.transform.TransformerException:
org.xml.sax.SAXParseException: Content is not allowed in prolog.
at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:501)
at Info.Mailer.getTextXML(Mailer.java:516)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction(ExtensionHandlerJavaClass.java:399)
at
org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction(ExtensionHandlerJavaClass.java:438)
at
org.apache.xalan.extensions.ExtensionsTable.extFunction(ExtensionsTable.java:220)
at
org.apache.xalan.transformer.TransformerImpl.extFunction(TransformerImpl.java:473)
at
org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:206)
at org.apache.xpath.XPath.execute(XPath.java:335)
at
org.apache.xalan.templates.ElemCopyOf.execute(ElemCopyOf.java:132)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2281)
at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1367)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1284)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1262)
at Info.Mailer.sendmail(Mailer.java:153)
at Info.Mailer.main(Mailer.java:27)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in
prolog.
at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
at
org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
Source)
at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
... 28 more
---------
org.xml.sax.SAXParseException: Content is not allowed in prolog.
at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
at
org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
Source)
at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
at Info.Mailer.getTextXML(Mailer.java:516)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction(ExtensionHandlerJavaClass.java:399)
at
org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction(ExtensionHandlerJavaClass.java:438)
at
org.apache.xalan.extensions.ExtensionsTable.extFunction(ExtensionsTable.java:220)
at
org.apache.xalan.transformer.TransformerImpl.extFunction(TransformerImpl.java:473)
at
org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:206)
at org.apache.xpath.XPath.execute(XPath.java:335)
at
org.apache.xalan.templates.ElemCopyOf.execute(ElemCopyOf.java:132)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2281)
at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1367)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1284)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1262)
at Info.Mailer.sendmail(Mailer.java:153)
at Info.Mailer.main(Mailer.java:27)