1 # $Id: NodeList.pm 785 2009-07-16 14:17:46Z pajas $
3 # This is free software, you may use it and distribute it under the same terms as
6 # Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas
10 package XML::LibXML::NodeList;
12 use XML::LibXML::Boolean;
13 use XML::LibXML::Literal;
14 use XML::LibXML::Number;
16 use vars qw ($VERSION);
17 $VERSION = "1.70"; # VERSION TEMPLATE: DO NOT CHANGE
21 'bool' => \&to_boolean,
30 my ($class,$array_ref,$reuse) = @_;
31 return bless $reuse ? $array_ref : [@$array_ref], $class;
35 my $self = CORE::shift;
40 my $self = CORE::shift;
41 CORE::push @$self, @_;
45 my $self = CORE::shift;
47 CORE::push @$self, $nodelist->get_nodelist;
51 my $self = CORE::shift;
56 my $self = CORE::shift;
57 CORE::unshift @$self, @_;
61 my $self = CORE::shift;
63 CORE::unshift @$self, $nodelist->get_nodelist;
67 my $self = CORE::shift;
72 # uses array index starting at 1, not 0
73 # this is mainly because of XPath.
74 my $self = CORE::shift;
82 my $self = CORE::shift;
87 my $self = CORE::shift;
88 return (@$self > 0) ? XML::LibXML::Boolean->True : XML::LibXML::Boolean->False;
91 # string-value of a nodelist is the string-value of the first node
93 my $self = CORE::shift;
94 return '' unless @$self;
95 return $self->[0]->string_value;
99 my $self = CORE::shift;
100 return XML::LibXML::Literal->new(
101 join('', grep {defined $_} map { $_->string_value } @$self)
106 my $self = CORE::shift;
107 return XML::LibXML::Number->new(
113 warn "this function is obsolete!\nIt was disabled in version 1.54\n";
122 XML::LibXML::NodeList - a list of XML document nodes
126 An XML::LibXML::NodeList object contains an ordered list of nodes, as
127 detailed by the W3C DOM documentation of Node Lists.
131 my $results = $dom->findnodes('//somepath');
132 foreach my $context ($results->get_nodelist) {
133 my $newresults = $context->findnodes('./other/element');
141 You will almost never have to create a new NodeSet object, as it is all
142 done for you by XPath.
144 =head2 get_nodelist()
146 Returns a list of nodes, the contents of the node list, as a perl list.
148 =head2 string_value()
150 Returns the string-value of the first node in the list.
151 See the XPath specification for what "string-value" means.
155 Returns the concatenation of all the string-values of all
156 the nodes in the list.
158 =head2 get_node($pos)
160 Returns the node at $pos. The node position in XPath is based at 1, not 0.
164 Returns the number of nodes in the NodeSet.
168 Equivalent to perl's pop function.
172 Equivalent to perl's push function.
174 =head2 append($nodelist)
176 Given a nodelist, appends the list of nodes in $nodelist to the end of the
181 Equivalent to perl's shift function.
183 =head2 unshift(@nodes)
185 Equivalent to perl's unshift function.
187 =head2 prepend($nodeset)
189 Given a nodelist, prepends the list of nodes in $nodelist to the front of
194 Will return a new nodelist iterator for the current nodelist. A
195 nodelist iterator is usefull if more complex nodelist processing is