简体   繁体   English

元素类型“ META”必须以匹配的结束标记“ </META> ”。 使用XSL从XML文件生成PDF时

[英]The element type “META” must be terminated by the matching end-tag “</META>”. while generating PDF from XML file using XSL

Am trying to convert XML to PDF document. 我正在尝试将XML转换为PDF文档。 While parsing XML with XSL for generating HTML for PDF creating. 同时使用XSL解析XML以生成用于创建PDF的HTML。 HTML doesnt contain </meta> closing tag, due to that am getting the below error HTML不包含</meta>结束标记,因为它收到以下错误

 Exception in thread "main" org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). org.xml.sax.SAXParseException; lineNumber: 22; columnNumber: 3; The element type "META" must be terminated by the matching end-tag "</META>".

How i can include </meta> closing tag in HTML 我如何在HTML中包含</meta>结束标记

Please find my java code to generate PDF from XML 请找到我的Java代码以从XML生成PDF

public class XMLtoPDF {


     public static void main(String[] args) 
                throws IOException, DocumentException, TransformerException,TransformerConfigurationException,FileNotFoundException {



            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer(new StreamSource("xsl_html_pagebreak_a.xslt"));
            transformer.transform(new StreamSource("xsl_html_pagebreak_input.xml"),new StreamResult(new FileOutputStream("sample3.html")));
            String File_To_Convert = "sample3.html";
            String url = new File(File_To_Convert).toURI().toURL().toString();
            System.out.println(""+url);
            String HTML_TO_PDF = "ConvertedFile3.pdf";
            OutputStream os = new FileOutputStream(HTML_TO_PDF);       
            ITextRenderer renderer = new ITextRenderer();
            renderer.setDocument(url);      
            renderer.layout();
            renderer.createPDF(os);        
            os.close();
        }
}

The name org.xhtmlrenderer.util suggests to me that the library you are using (ITextRenderer) expects XHTML. 名称org.xhtmlrenderer.util向我暗示您正在使用的库(ITextRenderer)需要XHTML。 You can get XHTML output from your XSLT transformation by 您可以通过以下方式从XSLT转换中获取XHTML输出:

(a) changing it to use the XHTML output method instead of HTML (a)将其更改为使用XHTML输出方法而不是HTML

(b) changing it to use an XSLT 2.0 processor such as Saxon, because to use the XHTML output method, you need XSLT 2.0. (b)更改它以使用XSLT 2.0处理器(例如Saxon),因为要使用XHTML输出方法,则需要XSLT 2.0。

More specifically, change 更具体地说,改变

TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource("xsl_html_pagebreak_a.xslt"));

to

TransformerFactory tFactory = new net.sf.saxon.TransformerFactoryImpl();
Transformer transformer = tFactory.newTransformer(new StreamSource("xsl_html_pagebreak_a.xslt"));
transformer.setOutputProperty("method", "xhtml");

Alternatively you might find that changing the serialization method to "xml" will also work; 另外,您可能会发现将序列化方法更改为“ xml”也可以使用; in that case you don't need to change to XSLT 2.0. 在这种情况下,您无需更改为XSLT 2.0。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 元素类型“META”必须以匹配的结束标签“</META> ” - The element type “META” must be terminated by the matching end-tag “</META>” XMLStreamException:[row,col]:[5,3]处的ParseError消息:元素类型“ meta”必须由匹配的结束标记“ </meta> ” - XMLStreamException: ParseError at [row,col]:[5,3] Message: The element type “meta” must be terminated by the matching end-tag “</meta>” SaxParseException 元素类型“hr”必须由匹配的结束标记“终止</hr> “。在使用 jaxb 读取 xml 时 - SaxParseException The element type "hr" must be terminated by the matching end-tag "</hr>". while reading xml with jaxb 元素类型“主机”必须以匹配的结束标记“ </Host> ” - The element type “Host” must be terminated by the matching end-tag “</Host>” 无效的 XML:第 6 行错误:元素类型“hr”必须由匹配的结束标记“终止”</hr> ” - Invalid XML: Error on line 6: The element type “hr” must be terminated by the matching end-tag “</hr>” Pom.xml:元素类型“dependencies”必须由匹配的end-tag“”终止 - Pom.xml: The element type “dependencies” must be terminated by the matching end-tag “</dependencies>” maven web.xml 元素类型“web-app”必须由匹配的结束标记“”终止 - maven web.xml The element type "web-app" must be terminated by the matching end-tag "</web- app>" Digester:元素类型“user”必须由匹配的结束标签“”终止 - Digester: The element type “user” must be terminated by the matching end-tag “</user>” 无法解析配置:hibernate.cfg.xml:元素类型“ session-factory”必须由匹配的结束标记“ </session-factory> ” - Could not parse configuration: hibernate.cfg.xml: The element type “session-factory” must be terminated by the matching end-tag “</session-factory>” “清单”必须以匹配的结束标签“ </manifest> ” - “manifest” must be terminated by the matching end-tag “</manifest>”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM