how to solve [org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 1; Content is not allowed in prolog.]

Alex Source

I want to generate a pdf from an xsl template and xml parameters,

the beginning of the template is the next one:

< ?xml version="1.0" encoding="UTF-8"?> < xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format" >
< xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes" encoding="UTF-8" />**

and the bebinning of the xml file:

< ?xml version="1.0" encoding="UTF-8" ?>
< GenerationReport >
< ValidationResult >
< Result >...

the error that is coming out:

Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 1; Content is not allowed in prolog. at org.apache.xerces.parsers.DOMParser.parse(DOMParser.java:244) at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:285) at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) at es.gob.signaturereport.tools.XMLUtils.getDocumentImpl(XMLUtils.java:371) at es.gob.signaturereport.tools.XMLUtils.getDocument(XMLUtils.java:233) ... 53 more

xmlxsltxsl-fo

Answers

answered 2 months ago Tony Graham #1

@joel-m-lamsen is correct that you don't want a space in <?.

However, you also don't want a space between < and the element name. Your samples should be (with line-breaks added to avoid scroll bars):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:fo="http://www.w3.org/1999/XSL/Format" >
  <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"
    encoding="UTF-8" />

and:

<?xml version="1.0" encoding="UTF-8" ?>
<GenerationReport >
  <ValidationResult >
    <Result >...

The space before the >, />, or ?> isn't a problem. (Just don't start adding spaces in /> or ?>.)

comments powered by Disqus