如何使javax变压器输出HTML(没有自闭标签)? [英] How to make javax Transformer output HTML (no self-closing tags)?

查看:136
本文介绍了如何使javax变压器输出HTML(没有自闭标签)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 javax.xml.transform.Transformer 将XML文件转换为HTML文件。可能发生的情况是, div 将没有内容,导致Transformer输出< div /> 这会中断渲染。

I'm using a javax.xml.transform.Transformer to convert an XML file into an HTML file. It can happen that a div will have no content, which causes the Transformer to output <div/>, which breaks rendering.

我搜索过并且找到你可以将xslt输出更改为html 而不是xml以避免自闭标签的问题,但那是对于不同的工具,我还想知道:我该怎么做,使用 javax Transformer

I've searched and found that "You can change the xslt output to html instead of xml to avoid the problem with self closing tags", but that was for a different tool and I'm left wondering: how do I do that with a javax Transformer?

推荐答案

这个答案在另一个线程似乎不适用于我的情况;即使我指定< xsl:output method =html...> ,它仍会产生< div /> 而不是< div>< / div>

This answer in another thread doesn't seem to work in my case; even if I specify <xsl:output method="html"...> it still produces <div/> instead of <div></div>.

我不知道我的IDE或编译器坏了(IBM Rational Application Developer),但我正在使用一种检测空白节点并在其中插入单个空格的解决方法。不那么干净,但有效......

I don't know if my IDE or compiler is broken (IBM Rational Application Developer), but I'm using a work-around of detecting blank nodes and inserting single spaces in them. Less clean, but effective...

这篇关于如何使javax变压器输出HTML(没有自闭标签)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆