在大型XML文件中转义字符 [英] Escaping characters in large XML files

查看:86
本文介绍了在大型XML文件中转义字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有100兆MB的大型XML文件.

I have large XML files of 100s of MB.

是否有任何实用程序可以解析XML文件并以字符串形式转义特殊字符而无需立即将整个文件打开到内存中?

Are there any utilities that can parse XML files and escape special charaters in strings without opening the entire file into memory at once?

谢谢

推荐答案

以下c ++程序一个字节一个字节地复制一个文件,它使用的内存很少(这使它有点慢). 您可以通过不经常刷新输出文件来提高性能.

The following c++ program copies a file byte by byte, and it uses very little memory (which makes it a little bit slow). You can improve the performance by not flushing to the outfile that often.

// copy a file using associated buffer's members
#include <fstream>
using namespace std;

int main () {
    char ch;
    ifstream infile;
    ofstream outfile;

    infile.open ("original.xml",std::ifstream::binary);
    outfile.open ("copy.xml",std::ofstream::binary);

    while ( !infile.eof() )
    {
        infile >> ch;
        outfile << ch;
        outfile.flush();
    }

    outfile.close();
    infile.close();

    return 0;
}

如果您要使用Unix工具,我想您可以使用 sed .

If you want a unix tool, I guess you could use sed.

这篇关于在大型XML文件中转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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