1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!perl
use strict;
use warnings;
use CGI;
use XML::Twig::XPath;
my $t= XML::Twig->new(pretty_print => 'indented',
twig_handlers => {
my $Xeu4a = $t -> get_xpath ('find/find/work[@root='a']');
my $Xeu4b = $t -> get_xpath ('find/find/work[@root='b']');
my $Xeu4c = $t -> get_xpath ('find/find/work[@root='c']');
my $Xeu4d = $t -> get_xpath ('find/find/work[@root='d']');
my $Xeu4e = $t -> get_xpath ('find/find/work[@root='e']');
}
$Xeu4a =~ s/(\d)(?=(\d{3})+(?!\d))/$1 /g;
print $Xeu4a->text,"\n",
$Xeu4b =~ s/(\d)(?=(\d{3})+(?!\d))/$1 /g;
print $Xeu4b->text,"\n",
);
$t->parseurl('http://arenas.pagesperso-orange.fr/divers/find.xml');
flush($X*);
$Xvar = ([xml]$xdxml).selectSingleNode("//work/root/@eu").$xt usw.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!perl
use strict;
use warnings;
use XML::LibXML;
our ($XVal) = '';
my $dom = XML::LibXML->new->parse_file('C:/studio/divers/find.xml');
$dom -> (IO => \*DATA) or die;
for my $node ($dom->findnodes('/././././@eu'))
{say $node->toString;}
$XVal = $dom->get_xpath('/././././[@eu="d"]')
{say $XVal->toString;}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<find> <find group="1"> <work eu="4"> <root a="1254" b="248" c="2496" d="1248"/> </work> <work Nus="9"> <root a="254" b="203" c="121" d="12" e="0"/> </work> <work Mus="2"> <root a="541" b="313" c="17" d="72" e="12" g="14"/> </work> <work Sus="7"> <root a="614" b="923" c="312" d="46" e="1534"/> </work> </find> <find group="2"> ... </find> </find>
Quote2015-06-15T19:15:13 Linuxer
Und was willst Du nun genau machen/erreichen?
- Du willst die Attributs-Werte vom root-Element von "work eu=4"?
- Du willst die Attributs-Werte von den root-Elemente von allen "work eu=", egal welchen Wert "eu" hat.
- Du willst die Attributs-Werte von a in den "root"-Elemente aller "work X"?
<work eu="4"><root a="1254" b="248" c="2496" d="1248"/>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#! perl use strict; use warnings; use v5.010.000; # enable "say" and other stuff use XML::Twig::XPath; use Data::Dumper; # for checking data structures my $t = XML::Twig->new( pretty_print => 'indented', twig_roots => { 'work' => \&fetch }, ); sub fetch { my ( $t, $work ) = @_; my %data; # limit actions to "<work eu=...>" if ( exists $work->{att}->{eu} ) { # hopefully only one root within "<work ...>" my $root = $work->first_child('root'); # save attribute data in hash %data %data = %{ $root->{att} }; # work with hash %data do_your_math( %data ); } } sub do_your_math { my %data = @_; # show content of %data print Data::Dumper->new( [ \%data ], [ '*data' ] )->Dump(); } $t->parseurl("http://arenas.pagesperso-orange.fr/divers/find.xml");
QuoteFrage:
Die Daten in "%data" sind arrays? Ich Vermute es. Soweit bin ich noch nicht. Wie kann ich das Feststellen?
1
2
3
4
%data = (
key => 'value', # klassisches Schlüssel-Wert-Paar
otherkey => [ 1,2,3 ], # auch ein Schlüssel-Wert-Paar, aber als Wert ist hier eine Referenz auf ein Array, das 3 Elemente enthält
);