我通过 perl 脚本(如下所示)使用 XML::LibXML 创建以下 XML 文件:
more test.xml
<?xml version="1.0"?>
<books>
<computer/>
</books>
我的问题:如何删除“xml版本标题”:
<?xml version="1.0"?>
来自 test.xml 文件?在 perl 脚本中使用 DOM 命令?
为了仅获取 text.xml 文件中的以下行:
<books>
<computer/>
</books>
Yael
#
Perl 脚本:
#!/usr/bin/perl
use strict;
use warnings;
use XML::LibXML;
my $doc = XML::LibXML::Document->new;
my $root = $doc->createElement('books');
$doc->setDocumentElement($root);
my $computer = $doc->createElement('computer');
$root->appendChild($computer);
$doc->toFile('/var/tmp/test.xml');
好吧,关于我之前的评论,我现在找到了解决方案。
它似乎toFile
绕过$skipXMLDeclaration
然而toString
没有。所以以下工作:
$XML::LibXML::skipXMLDeclaration = 1;
my $doc = XML::LibXML::Document->new;
# create your document
print $doc->toString;
(非常小的)缺点是您必须自己编写文件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)