| Class | LibXML::XML::XPath::Object |
| In: |
ext/libxml/ruby_xml_xpath.c
|
| Parent: | Object |
A collection of nodes returned from the evaluation of an XML::XPath or XML::XPointer expression.
| context | [R] |
Dump libxml debugging information to stdout. Requires Libxml be compiled with debugging enabled.
/*
* call-seq:
* nodes.debug -> (true|false)
*
* Dump libxml debugging information to stdout.
* Requires Libxml be compiled with debugging enabled.
*/
VALUE
ruby_xml_xpath_object_debug(VALUE self) {
Call the supplied block for each node in this set.
/*
* call-seq:
* xpath_object.each { |node| ... } -> self
*
* Call the supplied block for each node in this set.
*/
VALUE
ruby_xml_xpath_object_each(VALUE self)
{
xmlXPathObjectPtr xpop;
int i;
if ( ruby_xml_xpath_object_empty_q(self) == Qtrue )
return Qnil;
Data_Get_Struct(self,xmlXPathObject,xpop);
for (i = 0; i < xpop->nodesetval->nodeNr; i++) {
rb_yield(ruby_xml_xpath_object_tabref(xpop,i));
}
return(self);
}
Determine whether this nodeset is empty (contains no nodes).
/*
* call-seq:
* xpath_object.empty? -> (true|false)
*
* Determine whether this nodeset is empty (contains no nodes).
*/
VALUE
ruby_xml_xpath_object_empty_q(VALUE self) {
Obtain the previous type object which is really just a proxy back to this object. Unless the type is not a NODESET, in which case it is nil.
/*
* call-seq:
* xpath_object.set -> Node::Set
*
* Obtain the previous type object which is really
* just a proxy back to this object. Unless the
* type is not a NODESET, in which case it is nil.
*/
VALUE
ruby_xml_xpath_object_set(VALUE self)
{
xmlXPathObjectPtr xpop;
VALUE r;
Data_Get_Struct(self,xmlXPathObject,xpop);
r=Qnil;
if (xpop->type == XPATH_NODESET)
r=ruby_xml_node_set_new2(self);
return r;
}
Returns the original XPath expression as a string.
/*
* call-seq:
* xpath_object.string -> String
*
* Returns the original XPath expression as a string.
*/
VALUE
ruby_xml_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);
}
Obtain an array of the nodes in this set.
/*
* call-seq:
* xpath_object.to_a -> [node, ..., node]
*
* Obtain an array of the nodes in this set.
*/
VALUE
ruby_xml_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 = ruby_xml_xpath_object_tabref(xpop, i);
rb_ary_push(set_ary, nodeobj);
}
}
return(set_ary);
}
Returns the XPath type of the result object. Possible values are defined as constants on the XML::XPath class and include:
/*
* call-seq:
* 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
*/
VALUE
ruby_xml_xpath_object_get_type(VALUE self)
{
xmlXPathObjectPtr xpop;
Data_Get_Struct(self,xmlXPathObject,xpop);
return INT2FIX(xpop->type);
}