写入xml时,XML :: LibXML删除标题
发布时间:2020-12-16 23:19:58 所属栏目:百科 来源:网络整理
导读:当我使用 XML :: Lib XML更新值时,前两行被删除. 我希望保留xml,除了一个更新的值. 我原来的xml是: ?xml version="1.0"??xml-stylesheet type="text/xsl" href="configuration.xsl"?configuration property nametest.name/name valuehelp/value description
当我使用
XML :: Lib
XML更新值时,前两行被删除.
我希望保留xml,除了一个更新的值. 我原来的xml是: <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>test.name</name> <value>help</value> <description>xml issue</description> </property> …. 代码是: my $parser =XML::LibXML->new(); my $tree =$parser->parse_file($file) or die $!; my $root =$tree->getDocumentElement; my $searchPath="/configuration/property[name="$name"]/value/text()"; my ($val)=$root->findnodes($searchPath); $val->setData($new_val); open (UPDXML,"> $file") or die "ERROR: Failed to write into $file..."; print UPDXML $root->toString(1); close (UPDXML); 我尝试使用print UPDXML $root-> toStringC14N(1),但它没有帮助…… 解决方法
daxim和rpg的答案都是这样做的,但要强调 – 使用$tree-> toString()而不是$root-> toString()来获取整个文件.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |