Class: LibXML::XML::XPath::Object
- Inherits:
-
Object
- Object
- LibXML::XML::XPath::Object
- Includes:
- Enumerable
- Defined in:
- ext/libxml/ruby_xml_xpath_object.c,
lib/libxml/xpath_object.rb,
ext/libxml/ruby_xml_xpath_object.c
Overview
A collection of nodes returned from the evaluation of an XML::XPath or XML::XPointer expression.
Instance Attribute Summary collapse
- #context ⇒ Object readonly
Instance Method Summary collapse
-
#[](aref) ⇒ Object
xpath_object -> node.
-
#debug ⇒ Object
Dump libxml debugging information to stdout.
-
#each {|node| ... } ⇒ self
Call the supplied block for each node in this set.
-
#empty? ⇒ Boolean
Determine whether this nodeset is empty (contains no nodes).
-
#first ⇒ Object
Returns the first node in this node set, or nil if none exist.
-
#length ⇒ Numeric
Obtain the length of the nodesetval node list.
- #set ⇒ Object
-
#length ⇒ Numeric
Obtain the length of the nodesetval node list.
-
#string ⇒ String
Returns the original XPath expression as a string.
-
#to_a ⇒ Array
Obtain an array of the nodes in this set.
-
#xpath_type ⇒ Integer
Returns the XPath type of the result object.
Instance Attribute Details
#context ⇒ Object (readonly)
Instance Method Details
#[](aref) ⇒ Object
xpath_object -> node
array index into set of nodes
205 206 207 208 209 210 211 212 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 205
static VALUE rxml_xpath_object_aref(VALUE self, VALUE aref)
{
if (rxml_xpath_object_empty_q(self) == Qtrue)
return Qnil;
return rxml_xpath_object_tabref((xmlXPathObjectPtr) DATA_PTR(self), NUM2INT(
aref));
}
|
#debug ⇒ Object
Dump libxml debugging information to stdout. Requires Libxml be compiled with debugging enabled.
285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 285
static VALUE rxml_xpath_object_debug(VALUE self)
{
xmlXPathObjectPtr xpop;
#ifndef LIBXML_DEBUG_ENABLED
rb_raise(rb_eTypeError, "libxml was not compiled with debug support.");
#endif
Data_Get_Struct(self, xmlXPathObject, xpop);
xmlXPathDebugDumpObject(stdout, xpop, 0);
return Qnil;
}
|
#each {|node| ... } ⇒ self
Call the supplied block for each node in this set.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 168
static VALUE rxml_xpath_object_each(VALUE self)
{
xmlXPathObjectPtr xpop;
int i;
if (rxml_xpath_object_empty_q(self) == Qtrue)
return Qnil;
Data_Get_Struct(self, xmlXPathObject, xpop);
for (i = 0; i < xpop->nodesetval->nodeNr; i++)
{
rb_yield(rxml_xpath_object_tabref(xpop, i));
}
return (self);
}
|
#empty? ⇒ Boolean
Determine whether this nodeset is empty (contains no nodes).
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 149
static VALUE rxml_xpath_object_empty_q(VALUE self)
{
xmlXPathObjectPtr xpop;
Data_Get_Struct(self, xmlXPathObject, xpop);
if (xpop->type != XPATH_NODESET)
return Qnil;
return (xpop->nodesetval == NULL || xpop->nodesetval->nodeNr <= 0) ? Qtrue
: Qfalse;
}
|
#first ⇒ Object
Returns the first node in this node set, or nil if none exist.
191 192 193 194 195 196 197 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 191
static VALUE rxml_xpath_object_first(VALUE self)
{
if (rxml_xpath_object_empty_q(self) == Qtrue)
return Qnil;
return rxml_xpath_object_tabref((xmlXPathObjectPtr) DATA_PTR(self), 0);
}
|
#length ⇒ Numeric
Obtain the length of the nodesetval node list.
220 221 222 223 224 225 226 227 228 229 230 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 220
static VALUE rxml_xpath_object_length(VALUE self)
{
xmlXPathObjectPtr xpop;
if (rxml_xpath_object_empty_q(self) == Qtrue)
return INT2FIX(0);
Data_Get_Struct(self, xmlXPathObject, xpop);
return INT2NUM(xpop->nodesetval->nodeNr);
}
|
#set ⇒ Object
5 6 7 8 |
# File 'lib/libxml/xpath_object.rb', line 5 def set warn("XPath::Object#set is deprecated. Simply use the XPath::Object API instead") self end |
#length ⇒ Numeric
Obtain the length of the nodesetval node list.
220 221 222 223 224 225 226 227 228 229 230 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 220
static VALUE rxml_xpath_object_length(VALUE self)
{
xmlXPathObjectPtr xpop;
if (rxml_xpath_object_empty_q(self) == Qtrue)
return INT2FIX(0);
Data_Get_Struct(self, xmlXPathObject, xpop);
return INT2NUM(xpop->nodesetval->nodeNr);
}
|
#string ⇒ String
Returns the original XPath expression as a string.
266 267 268 269 270 271 272 273 274 275 276 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 266
static VALUE rxml_xpath_object_string(VALUE self)
{
xmlXPathObjectPtr xpop;
Data_Get_Struct(self, xmlXPathObject, xpop);
if (xpop->stringval == NULL)
return Qnil;
return rb_str_new2((const char*) xpop->stringval);
}
|
#to_a ⇒ Array
Obtain an array of the nodes in this set.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 122
static VALUE rxml_xpath_object_to_a(VALUE self)
{
VALUE set_ary, nodeobj;
xmlXPathObjectPtr xpop;
int i;
Data_Get_Struct(self, xmlXPathObject, xpop);
set_ary = rb_ary_new();
if (!((xpop->nodesetval == NULL) || (xpop->nodesetval->nodeNr == 0)))
{
for (i = 0; i < xpop->nodesetval->nodeNr; i++)
{
nodeobj = rxml_xpath_object_tabref(xpop, i);
rb_ary_push(set_ary, nodeobj);
}
}
return (set_ary);
}
|
#xpath_type ⇒ Integer
Returns the XPath type of the result object. Possible values are defined as constants on the XML::XPath class and include:
-
XML::XPath::UNDEFINED
-
XML::XPath::NODESET
-
XML::XPath::BOOLEAN
-
XML::XPath::NUMBER
-
XML::XPath::STRING
-
XML::XPath::POINT
-
XML::XPath::RANGE
-
XML::XPath::LOCATIONSET
-
XML::XPath::USERS
-
XML::XPath::XSLT_TREE
251 252 253 254 255 256 257 258 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 251
static VALUE rxml_xpath_object_get_type(VALUE self)
{
xmlXPathObjectPtr xpop;
Data_Get_Struct(self, xmlXPathObject, xpop);
return INT2FIX(xpop->type);
}
|