Transformation error

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)
 
M

moralbarometer

hi joe, thx. the problem lies on less than and greater than signs in
this string: "<a>testing</a>"; I tried another approach by calling a
using a function in xsl that return this string. but the output of xsl
contains but &lt; and &gt; which the broswer doesn't understand. I
need these signs after calling the getting the string from the
function. Any idea?
thx
 
J

Joseph Kesselman

moralbarometer said:
but the output of xsl
contains but &lt; and &gt; which the broswer doesn't understand.

If you're outputting HTML for use in a browser, you should probably
consider setting the output mode to HTML rather than XML (see the
documentation for the xsl:eek:utput directive). That will switch to a
serializer which is more likely to be compatable with the typical browser.

But I think a browser which doesn't understand &lt; and &gt; should
probably be consdered broken...?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top