且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

perl + DOM + 使用 XML::LibXML + 如何从 XML 文件中删除 xml 版本标题?使用 DOM

更新时间:2023-11-07 11:36:28

好的,关于我之前的评论,我现在找到了解决方案.

Okay, regarding my previous comment, I now found a solution.

似乎 toFile 绕过了 $skipXMLDeclarationtoString 没有.所以以下工作:

It seems toFile bypasses $skipXMLDeclaration whereas toString doesn't. So the following works:

$XML::LibXML::skipXMLDeclaration = 1;

my $doc  = XML::LibXML::Document->new;
# create your document

print $doc->toString;

(非常小的)缺点是您必须自己编写文件.

The (very small) downside is that you have to write the file yourself.