1 |
## ------------------------------------------------------------------------- |
2 |
## $Id: XML.pm,v 1.2 2003/02/21 07:58:48 joko Exp $ |
3 |
## ------------------------------------------------------------------------- |
4 |
## $Log: XML.pm,v $ |
5 |
## ------------------------------------------------------------------------- |
6 |
|
7 |
|
8 |
package Data::Storage::Handler::AutoSymbol; |
9 |
|
10 |
use strict; |
11 |
use warnings; |
12 |
|
13 |
use base qw( |
14 |
DesignPattern::Object |
15 |
DesignPattern::Logger |
16 |
Data::Storage::Handler::Abstract |
17 |
); |
18 |
|
19 |
|
20 |
use Data::Dumper; |
21 |
|
22 |
|
23 |
sub sendQuery_tmp { |
24 |
my $self = shift; |
25 |
my $xpq = shift; |
26 |
my $options = shift; |
27 |
|
28 |
$self->log( "xpq='$xpq'", 'debug' ); |
29 |
|
30 |
# trace |
31 |
#print Dumper($self); |
32 |
#exit; |
33 |
|
34 |
my $file = $self->{filename}; |
35 |
|
36 |
if (!$file) { |
37 |
$self->log("No filename given.", 'error'); |
38 |
return; |
39 |
} |
40 |
|
41 |
if (! -e $file) { |
42 |
$self->log("File not found: '$file'.", 'error'); |
43 |
return; |
44 |
} |
45 |
|
46 |
#print "file: $file", "\n"; |
47 |
#print "xpq: $xpq", "\n"; |
48 |
|
49 |
# filter nodes by xpath-query |
50 |
my $xp = XML::XPath->new( filename => $file ); |
51 |
my $nodeset = $xp->find($xpq); |
52 |
|
53 |
# build result xml |
54 |
my $buffer; |
55 |
foreach my $node ($nodeset->get_nodelist) { |
56 |
$buffer .= XML::XPath::XMLParser::as_string($node) . "\n\n"; |
57 |
} |
58 |
#$buffer .= ''; |
59 |
#$buffer = "<result>$buffer</result>"; |
60 |
|
61 |
# trace |
62 |
#print $buffer, "\n"; |
63 |
#exit; |
64 |
|
65 |
$self->{buffer} = $buffer; |
66 |
|
67 |
} |
68 |
|
69 |
sub getResult_tmp { |
70 |
my $self = shift; |
71 |
return $self->{buffer}; |
72 |
} |
73 |
|
74 |
sub isEmpty_tmp { |
75 |
my $self = shift; |
76 |
return not defined $self->{buffer}; |
77 |
} |
78 |
|
79 |
sub getChildNodes { |
80 |
my $self = shift; |
81 |
|
82 |
my $storage = $self->{storage}; |
83 |
|
84 |
my $nodes; |
85 |
if (not ref $storage) { |
86 |
$nodes = [ $storage ]; |
87 |
} elsif (ref $storage eq 'HASH') { |
88 |
$nodes = [ sort keys %$storage ]; |
89 |
} |
90 |
|
91 |
return $nodes; |
92 |
|
93 |
} |
94 |
|
95 |
1; |
96 |
__END__ |