468,771 Members | 1,733 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

Transformation error

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.TransformerIdentityIm pl.transform(TransformerIdentityImpl.java:501)
at Info.Mailer.getTextXML(Mailer.java:516)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.xalan.extensions.ExtensionHandlerJavaCl ass.callFunction(ExtensionHandlerJavaClass.java:39 9)
at
org.apache.xalan.extensions.ExtensionHandlerJavaCl ass.callFunction(ExtensionHandlerJavaClass.java:43 8)
at
org.apache.xalan.extensions.ExtensionsTable.extFun ction(ExtensionsTable.java:220)
at
org.apache.xalan.transformer.TransformerImpl.extFu nction(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(Elem CopyOf.java:132)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.transformer.TransformerImpl.apply TemplateToNode(TransformerImpl.java:2281)
at
org.apache.xalan.transformer.TransformerImpl.trans formNode(TransformerImpl.java:1367)
at
org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:709)
at
org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1284)
at
org.apache.xalan.transformer.TransformerImpl.trans form(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.createS AXParseException(Unknown
Source)
at
org.apache.xerces.util.ErrorHandlerWrapper.fatalEr ror(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportErro r(Unknown
Source)
at org.apache.xerces.impl.XMLErrorReporter.reportErro r(Unknown
Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError (Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl$Prol ogDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl.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.TransformerIdentityIm pl.transform(TransformerIdentityImpl.java:484)
... 28 more
---------
org.xml.sax.SAXParseException: Content is not allowed in prolog.
at
org.apache.xerces.util.ErrorHandlerWrapper.createS AXParseException(Unknown
Source)
at
org.apache.xerces.util.ErrorHandlerWrapper.fatalEr ror(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportErro r(Unknown
Source)
at org.apache.xerces.impl.XMLErrorReporter.reportErro r(Unknown
Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError (Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl$Prol ogDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl.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.TransformerIdentityIm pl.transform(TransformerIdentityImpl.java:484)
at Info.Mailer.getTextXML(Mailer.java:516)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.xalan.extensions.ExtensionHandlerJavaCl ass.callFunction(ExtensionHandlerJavaClass.java:39 9)
at
org.apache.xalan.extensions.ExtensionHandlerJavaCl ass.callFunction(ExtensionHandlerJavaClass.java:43 8)
at
org.apache.xalan.extensions.ExtensionsTable.extFun ction(ExtensionsTable.java:220)
at
org.apache.xalan.transformer.TransformerImpl.extFu nction(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(Elem CopyOf.java:132)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:1374)
at
org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2411)
at
org.apache.xalan.transformer.TransformerImpl.apply TemplateToNode(TransformerImpl.java:2281)
at
org.apache.xalan.transformer.TransformerImpl.trans formNode(TransformerImpl.java:1367)
at
org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:709)
at
org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1284)
at
org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1262)
at Info.Mailer.sendmail(Mailer.java:153)
at Info.Mailer.main(Mailer.java:27)

Sep 24 '06 #1
3 1486
moralbarometer wrote:
javax.xml.transform.TransformerException:
org.xml.sax.SAXParseException: Content is not allowed in prolog.
Your input is not a well-formed XML document. You've probably made the
mistake of having non-whitespace text before the root element. Fix your
input.

http://www.w3.org/TR/2006/REC-xml11-...sec-prolog-dtd

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Sep 24 '06 #2
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

Joe Kesselman schrieb:
moralbarometer wrote:
javax.xml.transform.TransformerException:
org.xml.sax.SAXParseException: Content is not allowed in prolog.

Your input is not a well-formed XML document. You've probably made the
mistake of having non-whitespace text before the root element. Fix your
input.

http://www.w3.org/TR/2006/REC-xml11-...sec-prolog-dtd

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Sep 25 '06 #3
moralbarometer wrote:
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:output 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...?
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Sep 25 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Sergio del Amo | last post: by
reply views Thread by MIke | last post: by
4 posts views Thread by Kevin Dean | last post: by
1 post views Thread by Andrew Connell | last post: by
reply views Thread by Hugo Ferreira | last post: by
4 posts views Thread by =?Utf-8?B?REZC?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.