diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2003-01-26 19:35:03 +0000 |
---|---|---|
committer | <> | 2015-02-23 10:18:26 +0000 |
commit | a2d12bc84fb2af87dd1c0c6e5bc854554902cd67 (patch) | |
tree | 7665979c7c281b21971de576d93246a022bff649 /XPath/LocationPath.pm | |
download | perl-xml-xpath-master.tar.gz |
Imported from /home/lorry/working-area/delta_perl-xml-xpath/XML-XPath-1.13.tar.gz.HEADXML-XPath-1.13master
Diffstat (limited to 'XPath/LocationPath.pm')
-rw-r--r-- | XPath/LocationPath.pm | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/XPath/LocationPath.pm b/XPath/LocationPath.pm new file mode 100644 index 0000000..eb483d6 --- /dev/null +++ b/XPath/LocationPath.pm @@ -0,0 +1,61 @@ +# $Id: LocationPath.pm,v 1.8 2001/03/16 11:10:08 matt Exp $ + +package XML::XPath::LocationPath; +use XML::XPath::Root; +use strict; + +sub new { + my $class = shift; + my $self = []; + bless $self, $class; +} + +sub as_string { + my $self = shift; + my $string; + for (my $i = 0; $i < @$self; $i++) { + $string .= $self->[$i]->as_string; + $string .= "/" if $self->[$i+1]; + } + return $string; +} + +sub as_xml { + my $self = shift; + my $string = "<LocationPath>\n"; + + for (my $i = 0; $i < @$self; $i++) { + $string .= $self->[$i]->as_xml; + } + + $string .= "</LocationPath>\n"; + return $string; +} + +sub set_root { + my $self = shift; + unshift @$self, XML::XPath::Root->new(); +} + +sub evaluate { + my $self = shift; + # context _MUST_ be a single node + my $context = shift; + die "No context" unless $context; + + # I _think_ this is how it should work :) + + my $nodeset = XML::XPath::NodeSet->new(); + $nodeset->push($context); + + foreach my $step (@$self) { + # For each step + # evaluate the step with the nodeset + my $pos = 1; + $nodeset = $step->evaluate($nodeset); + } + + return $nodeset; +} + +1; |