Class LibXML::XML::XPath::Object

  1. ext/libxml/libxml.c
  2. lib/libxml/xpath_object.rb
  3. show all

A collection of nodes returned from the evaluation of an XML::XPath or XML::XPointer expression.

Included modules

  1. Enumerable

Attributes

context [R]

Public instance methods

xpath_object[i] → node

array index into set of nodes

[show source]
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));
}
nodes.debug → (true|false)

Dump libxml debugging information to stdout. Requires Libxml be compiled with debugging enabled.

[show source]
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
}
xpath_object.each { |node| ... } → self

Call the supplied block for each node in this set.

[show source]
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);
}
xpath_object.empty? → (true|false)

Determine whether this nodeset is empty (contains no nodes).

[show source]
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;
}
xpath_object.first → node

Returns the first node in this node set, or nil if none exist.

[show source]
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);
}
xpath_object.last → node

Returns the last node in this node set, or nil if none exist.

[show source]
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);
}
xpath_object.length → num

Obtain the length of the nodesetval node list.

[show source]
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 ()
[show source]
    # File lib/libxml/xpath_object.rb, line 9
 9:         def set
10:           warn("XPath::Object#set is deprecated.  Simply use the XPath::Object API instead")
11:           self
12:         end
size ()

Alias for length

xpath_object.string → String

Returns the original XPath expression as a string.

[show source]
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 rxml_str_new2((const char*) rxpop->xpop->stringval, rxpop->xdoc->encoding);
}
xpath_object.to_a → [node, ..., node]

Obtain an array of the nodes in this set.

[show source]
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_object.xpath_type → int

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
[show source]
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);
}