@JRubyMethod(name = "node_set") public IRubyObject node_set(ThreadContext context) { try { NodeList nodes = (NodeList) xpath.evaluate(this.context, XPathConstants.NODESET); XmlNodeSet result = new XmlNodeSet(context.getRuntime(), nodes); // result.relink_namespace(context); result.setInstanceVariable("@document", contextNode.document(context)); return result; } catch (XPathExpressionException xpee) { throw new RaiseException(XmlSyntaxError.getXPathSyntaxError(context)); } }
@JRubyMethod public IRubyObject evaluate(ThreadContext context, IRubyObject expr, IRubyObject handler) { String src = expr.convertToString().asJavaString(); try { if (!handler.isNil()) { xpath.setXPathFunctionResolver(new NokogiriXPathFunctionResolver(handler)); } XPathExpression xpathExpression = xpath.compile(src); return new XmlXpath( context.getRuntime(), (RubyClass) context.getRuntime().getClassFromPath("Nokogiri::XML::XPath"), xpathExpression, this.context); } catch (XPathExpressionException xpee) { throw new RaiseException(XmlSyntaxError.getXPathSyntaxError(context, xpee)); } }