从WS答案XML制作PDF时,XML字符(Unicode:0x2)无效

时间:2012-04-09 07:32:25

标签: java apache-fop

我正在做一些来自WS的xml报告。报告应该是PDF格式,所以我选择了fop库来制作它。当我尝试从xml中生成报告时,它位于我的计算机上的xml文件中,一切正常。 当我在WebServer上调用此方法时,问题就开始了。我在这一行上有例外:

transformer.transform(src, res);

例外是:

org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x2) was found in the element content of the document.

首先是(Unicode:0x1a)字符,但我用这个函数剪切了它:

   private static String stripNonValidXMLCharacters(String in) {

    if (in == null || ("".equals(in))) {
        return null;
    }
    StringBuffer out = new StringBuffer(in);
    for (int i = 0; i < out.length(); i++) {
        if (out.charAt(i) == 0x1a) {
            out.setCharAt(i, '-');
        }             
    }
    return out.toString();
}

然后来了(Unicode:0x2)字符。试图添加

    else if (out.charAt(i) == 0x2) {
        out.setCharAt(i, '-');
    }

无济于事。

我正在使用fop版本0.95。

0 个答案:

没有答案