source: trunk/gsdl/perllib/cpan/XML/XPath/LocationPath.pm@ 7909

Last change on this file since 7909 was 7909, checked in by mdewsnip, 20 years ago

CPAN module for processing XPath expressions.

  • Property svn:keywords set to Author Date Id Revision
File size: 1.0 KB
Line 
1# $Id: LocationPath.pm 7909 2004-08-06 05:11:55Z mdewsnip $
2
3package XML::XPath::LocationPath;
4use XML::XPath::Root;
5use strict;
6
7sub new {
8 my $class = shift;
9 my $self = [];
10 bless $self, $class;
11}
12
13sub as_string {
14 my $self = shift;
15 my $string;
16 for (my $i = 0; $i < @$self; $i++) {
17 $string .= $self->[$i]->as_string;
18 $string .= "/" if $self->[$i+1];
19 }
20 return $string;
21}
22
23sub as_xml {
24 my $self = shift;
25 my $string = "<LocationPath>\n";
26
27 for (my $i = 0; $i < @$self; $i++) {
28 $string .= $self->[$i]->as_xml;
29 }
30
31 $string .= "</LocationPath>\n";
32 return $string;
33}
34
35sub set_root {
36 my $self = shift;
37 unshift @$self, XML::XPath::Root->new();
38}
39
40sub evaluate {
41 my $self = shift;
42 # context _MUST_ be a single node
43 my $context = shift;
44 die "No context" unless $context;
45
46 # I _think_ this is how it should work :)
47
48 my $nodeset = XML::XPath::NodeSet->new();
49 $nodeset->push($context);
50
51 foreach my $step (@$self) {
52 # For each step
53 # evaluate the step with the nodeset
54 my $pos = 1;
55 $nodeset = $step->evaluate($nodeset);
56 }
57
58 return $nodeset;
59}
60
611;
Note: See TracBrowser for help on using the repository browser.