1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/perl
use strict;
use warnings;
use XML::LibXML;
my $filename = "base.xml";
my $parser = XML::LibXML->new();
my $doc = $parser->parse_file($filename);
my $query = "/base/text()";
my ($node) = $doc->findnodes($query); # man beachte die Klammern!
$node->setData('bla');
print $doc->toString;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/perl
use strict;
use warnings;
use XML::LibXML;
my $filename = "base.xml";
my $parser = XML::LibXML->new();
my $doc = $parser->parse_file($filename);
my $query = "/base/text()";
my $node = $doc->findnodes($query); # <- "my $node" statt "my ($node)"
$node->setData('bla');
print $doc->toString;
Can't locate object method "setData" via package "XML::LibXML::NodeList" at C:\Xitami\cgi-bin\Forum\director.pl line 15.
my $var = "blubb"; # << da brauch ich keine Klammern, das funktioniert trotzdem.
Quote[...]
findnodes evaluates the xpath expression (XPath 1.0) on the current node and returns the resulting node set as an array. In a scalar context returns a XML::LibXML::NodeList object.
[...]
my ($node) = $doc->findnodes($query);
my $node = $doc->findnodes($query);
2010-10-15T14:01:24 NordlichtWird einem sowas in "Programmieren mit Perl" (O'Reilly) erklärt? Wenn ja, hab ich das wohl übersprungen ^^