class LibXML::XML::XPath::Object
A collection of nodes returned from the evaluation of an XML::XPath or XML::XPointer expression.
Attributes
Public Instance Methods
Source
static VALUE rxml_xpath_object_aref(VALUE self, VALUE aref)
{
rxml_xpath_object *rxpopp;
if (rxml_xpath_object_empty_q(self) == Qtrue)
return Qnil;
TypedData_Get_Struct(self, rxml_xpath_object, &rxml_xpath_object_data_type, rxpopp);
return rxml_xpath_object_tabref(rxpopp->xpop, NUM2INT(aref));
}
xpath_object -> node
array index into set of nodes
Source
static VALUE rxml_xpath_object_debug(VALUE self)
{
#ifdef LIBXML_DEBUG_ENABLED
rxml_xpath_object *rxpopp;
TypedData_Get_Struct(self, rxml_xpath_object, &rxml_xpath_object_data_type, rxpopp);
xmlXPathDebugDumpObject(stdout, rxpopp->xpop, 0);
return Qtrue;
#else
rb_warn("libxml was compiled without debugging support.");
return Qfalse;
#endif
}
Dump libxml debugging information to stdout. Requires Libxml be compiled with debugging enabled.
Source
static VALUE rxml_xpath_object_each(VALUE self)
{
rxml_xpath_object *rxpopp;
int i;
if (rxml_xpath_object_empty_q(self) == Qtrue)
return Qnil;
TypedData_Get_Struct(self, rxml_xpath_object, &rxml_xpath_object_data_type, rxpopp);
for (i = 0; i < rxpopp->xpop->nodesetval->nodeNr; i++)
{
rb_yield(rxml_xpath_object_tabref(rxpopp->xpop, i));
}
return (self);
}
Call the supplied block for each node in this set.
Source
static VALUE rxml_xpath_object_empty_q(VALUE self)
{
rxml_xpath_object *rxpopp;
TypedData_Get_Struct(self, rxml_xpath_object, &rxml_xpath_object_data_type, rxpopp);
if (rxpopp->xpop->type != XPATH_NODESET)
return Qnil;
return (rxpopp->xpop->nodesetval == NULL || rxpopp->xpop->nodesetval->nodeNr <= 0) ? Qtrue
: Qfalse;
}
Determine whether this nodeset is empty (contains no nodes).
Source
static VALUE rxml_xpath_object_first(VALUE self)
{
rxml_xpath_object *rxpopp;
if (rxml_xpath_object_empty_q(self) == Qtrue)
return Qnil;
TypedData_Get_Struct(self, rxml_xpath_object, &rxml_xpath_object_data_type, rxpopp);
return rxml_xpath_object_tabref(rxpopp->xpop, 0);
}
Returns the first node in this node set, or nil if none exist.
Source
static VALUE rxml_xpath_object_last(VALUE self)
{
rxml_xpath_object *rxpopp;
if (rxml_xpath_object_empty_q(self) == Qtrue)
return Qnil;
TypedData_Get_Struct(self, rxml_xpath_object, &rxml_xpath_object_data_type, rxpopp);
return rxml_xpath_object_tabref(rxpopp->xpop, -1);
}
Returns the last node in this node set, or nil if none exist.
Source
static VALUE rxml_xpath_object_length(VALUE self)
{
rxml_xpath_object *rxpopp;
if (rxml_xpath_object_empty_q(self) == Qtrue)
return INT2FIX(0);
TypedData_Get_Struct(self, rxml_xpath_object, &rxml_xpath_object_data_type, rxpopp);
return INT2NUM(rxpopp->xpop->nodesetval->nodeNr);
}
Obtain the length of the nodesetval node list.
Source
static VALUE rxml_xpath_object_string(VALUE self)
{
rxml_xpath_object *rxpopp;
TypedData_Get_Struct(self, rxml_xpath_object, &rxml_xpath_object_data_type, rxpopp);
if (rxpopp->xpop->stringval == NULL)
return Qnil;
return rxml_new_cstr( rxpopp->xpop->stringval, rxpopp->xdoc->encoding);
}
Returns the original XPath expression as a string.
Source
static VALUE rxml_xpath_object_to_a(VALUE self)
{
VALUE set_ary, nodeobj;
rxml_xpath_object *rxpopp;
xmlXPathObjectPtr xpop;
int i;
TypedData_Get_Struct(self, rxml_xpath_object, &rxml_xpath_object_data_type, rxpopp);
xpop = rxpopp->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);
}
Obtain an array of the nodes in this set.
Source
static VALUE rxml_xpath_object_get_type(VALUE self)
{
rxml_xpath_object *rxpopp;
TypedData_Get_Struct(self, rxml_xpath_object, &rxml_xpath_object_data_type, rxpopp);
return INT2FIX(rxpopp->xpop->type);
}
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