English 中文(简体)
您能够利用XPath的定点NodeText功能,节省磁盘。
原标题:Can you save to disk using XPath s setNodeText function?
  • 时间:2012-04-09 19:38:35
  •  标签:
  • perl
  • xpath

I m 采用像“学校/学生”这样的XPath。 除了硬墙外,<代码>NodeText的功能吗? 我的改动似乎只是记忆中。

最佳回答

If I understand correctly, you are trying to change a document then write it to disk.

use XML::LibXML qw( );

my $parser = XML::LibXML->new();
my $doc    = $parser->parse_fh(...);
my $root   = $doc->documentElement();

for my $node ($root->findnodes( //school/student[4] )) {
   $node->removeChildNodes();
   $node->appendText("New text");
}

open(my $fh,  >:raw , ...) or die $!;
print($fh $doc->toString());
问题回答

您可以采用无证方法(getNodeAsXML处置XML结构。 产量等于是有效的XML(例如,没有头盔),但通常是trick。

my $str = $xp->getNodeAsXML();
print $str;

资料来源:





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签