Class: Nokogiri::XML::XPathContext

Inherits:
Object
  • Object
show all
Defined in:
ext/nokogiri/xml_xpath_context.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(nodeobj) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'ext/nokogiri/xml_xpath_context.c', line 45

static VALUE new(VALUE klass, VALUE nodeobj)
{
  xmlXPathInit();

  xmlNodePtr node ;
  Data_Get_Struct(nodeobj, xmlNode, node);

  xmlXPathContextPtr ctx = xmlXPathNewContext(node->doc);
  ctx->node = node ;
  return Data_Wrap_Struct(klass, 0, deallocate, ctx);
}

Instance Method Details

#evaluate(search_path) ⇒ Object

Evaluate the search_path returning an XML::XPath object.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'ext/nokogiri/xml_xpath_context.c', line 32

static VALUE evaluate(VALUE self, VALUE search_path)
{
  xmlXPathContextPtr ctx;
  Data_Get_Struct(self, xmlXPathContext, ctx);

  xmlChar* query = (xmlChar *)StringValuePtr(search_path);
  xmlXPathObjectPtr xpath = xmlXPathEvalExpression(query, ctx);
  if(xpath == NULL) {
    rb_raise(rb_eRuntimeError, "Couldn't evaluate expression '%s'", query);
  }
  return Nokogiri_wrap_xml_xpath(xpath);
}

#register_ns(prefix, uri) ⇒ Object

Register the namespace with prefix and uri.



14
15
16
17
18
19
20
21
22
23
24
# File 'ext/nokogiri/xml_xpath_context.c', line 14

static VALUE register_ns(VALUE self, VALUE prefix, VALUE uri)
{
  xmlXPathContextPtr ctx;
  Data_Get_Struct(self, xmlXPathContext, ctx);

  xmlXPathRegisterNs( ctx,
                      (const xmlChar *)StringValuePtr(prefix),
                      (const xmlChar *)StringValuePtr(uri)
  );
  return self;
}