2

我已经下载了 Stack Over Flow 站点的 xml 转储。在将转储传输到 mysql 数据库时,我一直遇到以下错误:出现异常:字符引用“某些字符集如 ”是无效的 XML 字符。

我使用 UltraEdit(它是一个 800 兆的文件)从文件中删除了一些字符,但是如果我删除了无效的字符集并运行解析器,我会收到识别更多无效字符的错误。关于如何解决这个问题的任何建议?

大家加油,

j

4

3 回答 3

2

XML 中允许的字符集在这里。如您所见,#x10 不是其中之一。如果这些存在于 stackoverflow 转储中,则它不符合 XML。

或者,您正在使用错误的字符编码读取 XML。

于 2009-06-16T13:17:10.317 回答
2

你用的是哪个转储?第一个版本存在问题(不仅是无效字符,而且还<出现在不应该出现的地方),但它们应该在第二个转储中得到修复。

对于它的价值,我使用两个正则表达式替换修复了原始中的无效字符。替换“�[12345678BCEF];” 和 "" 每个都带有 "?" - 当然,将它们都视为正则表达式。

于 2009-06-16T13:20:10.793 回答
1

你应该把你的文件转换成我用java开发的UTF-8,下面是我的转换

公共字符串 FileUTF8Cleaner(文件 xmlfile){

    String out = xmlfile+".utf8";
    if (new File(out).exists())
        System.out.println("### File conversion process ### Deleting utf8 file");
        new File(out).delete();
        System.out.println("### File conversion process ### Deleting utf8 file [DONE!]");

    try {
        System.out.println("### File conversion process ### Converting file");
        FileInputStream fis = new FileInputStream(xmlfile);
        DataInputStream in = new DataInputStream(fis);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;

        FileOutputStream fos = new FileOutputStream(out);

        while ((strLine = br.readLine()) != null) {

            fos.write(strLine.replaceAll("\\p{Cc}", "").getBytes());
            fos.write("\n".getBytes());
        }

        fos.close();
        fis.close();
        in.close();
        br.close();
        System.out.println("### File conversion process ### Converting file [DONE)]");

    } catch(Exception e) {
        e.printStackTrace();
    }

        System.out.println("### File conversion process ### Processing file : "+xmlfile.getAbsolutePath()+" [DONE!]");
        return out;

}
于 2011-03-18T23:01:07.860 回答