/* TODO: DOCUMENT ME */
static VALUE in_context(VALUE self, VALUE _str, VALUE _options)
{
xmlNodePtr node;
xmlNodePtr list;
xmlNodeSetPtr set;
VALUE doc, err;
Data_Get_Struct(self, xmlNode, node);
if(!node->parent)
rb_raise(rb_eRuntimeError, "no contextual parsing on unlinked nodes");
doc = DOC_RUBY_OBJECT(node->doc);
err = rb_iv_get(doc, "@errors");
xmlSetStructuredErrorFunc((void *)err, Nokogiri_error_array_pusher);
/* Twiddle global variable because of a bug in libxml2.
* http://git.gnome.org/browse/libxml2/commit/?id=e20fb5a72c83cbfc8e4a8aa3943c6be8febadab7
*/
#ifndef HTML_PARSE_NOIMPLIED
htmlHandleOmittedElem(0);
#endif
xmlParseInNodeContext(
node,
StringValuePtr(_str),
(int)RSTRING_LEN(_str),
(int)NUM2INT(_options),
&list);
#ifndef HTML_PARSE_NOIMPLIED
htmlHandleOmittedElem(1);
#endif
xmlSetStructuredErrorFunc(NULL, NULL);
set = xmlXPathNodeSetCreate(NULL);
while(list) {
xmlXPathNodeSetAddUnique(set, list);
list = list->next;
}
return Nokogiri_wrap_xml_node_set(set, doc);
}