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.
-
#last ⇒ Object
Returns the last node in this node set, or nil if none exist.
-
#length ⇒ Numeric
(also: #size)
Obtain the length of the nodesetval node list.
- #set ⇒ Object
-
#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
229 230 231 232 233 234 235 236 237 238 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 229
static VALUE rxml_xpath_object_aref(VALUE self, VALUE aref)
{
rxml_xpath_object *rxpop;
if (rxml_xpath_object_empty_q(self) == Qtrue)
return Qnil;
Data_Get_Struct(self, rxml_xpath_object, rxpop);
return rxml_xpath_object_tabref(rxpop->xpop, NUM2INT(aref));
}
|
#debug ⇒ Object
Dump libxml debugging information to stdout. Requires Libxml be compiled with debugging enabled.
308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 308
static VALUE rxml_xpath_object_debug(VALUE self)
{
#ifdef LIBXML_DEBUG_ENABLED
rxml_xpath_object *rxpop;
Data_Get_Struct(self, rxml_xpath_object, rxpop);
xmlXPathDebugDumpObject(stdout, rxpop->xpop, 0);
return Qtrue;
#else
rb_warn("libxml was compiled without debugging support.")
return Qfalse;
#endif
}
|
#each {|node| ... } ⇒ self
Call the supplied block for each node in this set.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 172
static VALUE rxml_xpath_object_each(VALUE self)
{
rxml_xpath_object *rxpop;
int i;
if (rxml_xpath_object_empty_q(self) == Qtrue)
return Qnil;
Data_Get_Struct(self, rxml_xpath_object, rxpop);
for (i = 0; i < rxpop->xpop->nodesetval->nodeNr; i++)
{
rb_yield(rxml_xpath_object_tabref(rxpop->xpop, i));
}
return (self);
}
|
#empty? ⇒ Boolean
Determine whether this nodeset is empty (contains no nodes).
154 155 156 157 158 159 160 161 162 163 164 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 154
static VALUE rxml_xpath_object_empty_q(VALUE self)
{
rxml_xpath_object *rxpop;
Data_Get_Struct(self, rxml_xpath_object, rxpop);
if (rxpop->xpop->type != XPATH_NODESET)
return Qnil;
return (rxpop->xpop->nodesetval == NULL || rxpop->xpop->nodesetval->nodeNr <= 0) ? Qtrue
: Qfalse;
}
|
#first ⇒ Object
Returns the first node in this node set, or nil if none exist.
195 196 197 198 199 200 201 202 203 204 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 195
static VALUE rxml_xpath_object_first(VALUE self)
{
rxml_xpath_object *rxpop;
if (rxml_xpath_object_empty_q(self) == Qtrue)
return Qnil;
Data_Get_Struct(self, rxml_xpath_object, rxpop);
return rxml_xpath_object_tabref(rxpop->xpop, 0);
}
|
#last ⇒ Object
Returns the last node in this node set, or nil if none exist.
212 213 214 215 216 217 218 219 220 221 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 212
static VALUE rxml_xpath_object_last(VALUE self)
{
rxml_xpath_object *rxpop;
if (rxml_xpath_object_empty_q(self) == Qtrue)
return Qnil;
Data_Get_Struct(self, rxml_xpath_object, rxpop);
return rxml_xpath_object_tabref(rxpop->xpop, -1);
}
|
#length ⇒ Numeric Also known as: size
Obtain the length of the nodesetval node list.
246 247 248 249 250 251 252 253 254 255 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 246
static VALUE rxml_xpath_object_length(VALUE self)
{
rxml_xpath_object *rxpop;
if (rxml_xpath_object_empty_q(self) == Qtrue)
return INT2FIX(0);
Data_Get_Struct(self, rxml_xpath_object, rxpop);
return INT2NUM(rxpop->xpop->nodesetval->nodeNr);
}
|
#set ⇒ Object
7 8 9 10 |
# File 'lib/libxml/xpath_object.rb', line 7 def set warn("XPath::Object#set is deprecated. Simply use the XPath::Object API instead") self end |
#string ⇒ String
Returns the original XPath expression as a string.
289 290 291 292 293 294 295 296 297 298 299 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 289
static VALUE rxml_xpath_object_string(VALUE self)
{
rxml_xpath_object *rxpop;
Data_Get_Struct(self, rxml_xpath_object, rxpop);
if (rxpop->xpop->stringval == NULL)
return Qnil;
return rb_str_new2((const char*) rxpop->xpop->stringval);
}
|
#to_a ⇒ Array
Obtain an array of the nodes in this set.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 124
static VALUE rxml_xpath_object_to_a(VALUE self)
{
VALUE set_ary, nodeobj;
rxml_xpath_object *rxpop;
xmlXPathObjectPtr xpop;
int i;
Data_Get_Struct(self, rxml_xpath_object, rxpop);
xpop = rxpop->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
276 277 278 279 280 281 |
# File 'ext/libxml/ruby_xml_xpath_object.c', line 276
static VALUE rxml_xpath_object_get_type(VALUE self)
{
rxml_xpath_object *rxpop;
Data_Get_Struct(self, rxml_xpath_object, rxpop);
return INT2FIX(rxpop->xpop->type);
}
|