gpt4 book ai didi

xml - 如何从 XML::Simple::XMLout 压缩 XML?

转载 作者:数据小太阳 更新时间:2023-10-29 02:48:45 26 4
gpt4 key购买 nike

我正在使用 XML::Simple 来解析和编辑一个非常大的 XML 文件,速度是必不可少的(到目前为止,在我尝试过的所有方法中,XML::Simple 是最快的)

现在,一旦我完成了所有编辑,我就使用 XMLout() 将 XML 打印到文档中,尽管它以适当的缩进打印它,这对于人类阅读来说很好,但在我的情况下完全没用。

没有空格的输出文件是 1.2 Mb,有空格是 15 Mb。

我一直在使用:

my $string = XMLout($data);
$string =~ s/>[\s]*</></g;
print $out $string;

但它似乎不仅是一个极端的 CPU pig ,而且需要大量的内存。

他们是一种简单地将我的 XML 对象输出为正确的 XML 而没有所有无用的空白的方法吗?

谢谢

最佳答案

查看 NoIndent 选项:来自 XML::Simple 联机帮助页:

NoIndent => 1 # out - seldom used

Set this option to 1 to disable "XMLout()"’s default ’pretty printing’ mode. With this option enabled, the XML output will all be on one line (unless there are newlines in the data) - this may be easier for downstream processing.

NormaliseSpace => 0 │ 1 │ 2 # in - handy

This option controls how whitespace in text content is handled. Recognised values for the option are:

  • 0 = (default) whitespace is passed through unaltered (except of course for the normalisation of whitespace in attribute values which is mandated by the XML recommendation)

  • 1 = whitespace is normalised in any value used as a hash key (normalising means removing leading and trailing whites- pace and collapsing sequences of whitespace characters to a single space)

  • 2 = whitespace is normalised in all text content

    Note: you can spell this option with a ’z’ if that is more natural for you.

关于xml - 如何从 XML::Simple::XMLout 压缩 XML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4127360/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com