【发布时间】:2011-12-18 15:04:29
【问题描述】:
我有一个 XML 文件并使用以下代码对其进行解析:
open( $filehandle, "+<$path") or die "cannot open out file out_file:$!";
my $roots = { tag1 => 1 };
my $handlers = { 'tag0/tag1' => $tweak_server,
};
my $twig = new XML::Twig(TwigRoots => $roots,
TwigHandlers => $handlers,
pretty_print => 'indented',
twig_print_outside_roots => \*$filehandle
);
$twig->parsefile($path);
$twig->flush($filehandle, pretty_print => 'indented');
close $filehandle;
在输出中,所有tag1部分的格式都很好。它们只是原始格式,但文件的其余部分格式不正确。标签之间有一些空行,更重要的是,元素内的文本内容添加了一些不应该存在的空行。
有没有办法将 XML 文件的其余部分解析为原始格式?
【问题讨论】: