Method: LibXML::XML::XPath::Expression#initialize

Defined in:
ext/libxml/ruby_xml_xpath_expression.c

#XPath::Expression.new(expression) ⇒ XPath::Expression

Compiles an XPatch expression. This improves performance when an XPath expression is called multiple times.

doc = XML::Document.string('<header><first>hi</first></header>')
expr = XPath::Expression.new('//first')
nodes = doc.find(expr)


63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'ext/libxml/ruby_xml_xpath_expression.c', line 63

static VALUE rxml_xpath_expression_initialize(VALUE self, VALUE expression)
{
  xmlXPathCompExprPtr compexpr = xmlXPathCompile((const xmlChar*)StringValueCStr(expression));

  if (compexpr == NULL)
  {
    xmlErrorPtr xerror = xmlGetLastError();
    rxml_raise(xerror);
  }

  DATA_PTR( self) = compexpr;
  return self;
}