因为工作的要求,需要将xml文件转换成html文件,然后将html代码片段嵌入jsp使用
我的xml文件使用报表设计器制作的,所以标签和数据都封装在xml文件里。java的作用就是将xml解析成对应格式的html文件。
整了好几天也没弄出来,望各位大虾指点一二,在下感激不尽
用到的简单的xml文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<background>
<band/>
</background>
<title>
<band height="36">
<textField>
<reportElement x="217" y="9" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[test]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band/>
</pageHeader>
<columnHeader>
<band/>
</columnHeader>
<detail>
<band>
<textField>
<reportElement x="336" y="54" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[sex]]></textFieldExpression>
</textField>
<textField>
<reportElement x="178" y="54" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[age]]></textFieldExpression>
</textField>
<textField>
<reportElement x="27" y="54" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[name]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band/>
</columnFooter>
<pageFooter>
<band height="145">
<staticText>
<reportElement x="216" y="110" width="100" height="20"/>
<textElement/>
<text><![CDATA[65465566565]]></text>
</staticText>
<textField>
<reportElement x="353" y="116" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{field}]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band/>
</summary>
</jasperReport>

解决方案 »

  1.   

    最终想要的html代码格式大概是这样的:
    <table>
    <tr>
    <td>name</td>
    <td>age</td>
    <td>sex</td>
    </tr>
    ````````
    </table>
      

  2.   

    ....两天.... 我估计一周搞出来就很不错了...
    你仅是要从 .jrxml转成 html吗?
    估计 还是要用 div 好些, table 用来保存各个 band...如果你还要 从 html 转成 jrxml,够你头痛的
      

  3.   

    在jrxml中既包含了数据,又包含了数据的格式,
    要的就是jrxml转换成html
    大侠,帮帮忙了
      

  4.   

    不好转的, 我接触的也说就是从 html 转成 xml, 不过还不是我写的你要 jrxml 转成 html,  最好还是自己写个转换吧提供个思路先转成 jasperDesign 对象, 然后再把 jrband 转成 行, 可能也需要转成列然后把 jrelement 转成 div 放到每个 jr 中, 注意位置...没试过,具体的还需要自己考虑
      

  5.   

    谢了,不过这东西是需要花时间的,要熟悉 html,css, 可能还要熟悉 js