Class | LibXML::XML::XPath::Context |
In: |
ext/libxml/ruby_xml_xpath.c
|
Parent: | Object |
The XML::XPath::Context class is used to evaluate XPath expressions. Generally, you should not directly use this class, but instead use the XML::Document#find and XML::Node#find methods.
doc = XML::Document.string('<header>content</header>') context = XPath::Context.new(doc) context.node = doc.root context.register_namespaces_from_node(doc.root) nodes = context.find('/header')
doc | [R] |
Creates a new XPath context for the specified document. The context can then be used to evaluate an XPath expression.
doc = XML::Document.string('<header><first>hi</first></header>') context = XPath::Context.new(doc) nodes = XPath::Object.new('//first', context) nodes.length == 1
/* call-seq: * XPath::Context.new(node) -> XPath::Context * * Creates a new XPath context for the specified document. The * context can then be used to evaluate an XPath expression. * * doc = XML::Document.string('<header><first>hi</first></header>') * context = XPath::Context.new(doc) * nodes = XPath::Object.new('//first', context) * nodes.length == 1 */ VALUE ruby_xml_xpath_context_initialize(VALUE self, VALUE node) {
Set the current node used by the XPath engine
doc = XML::Document.string('<header><first>hi</first></header>') context.node = doc.root.first
/* * call-seq: * context.node = node * * Set the current node used by the XPath engine * doc = XML::Document.string('<header><first>hi</first></header>') * context.node = doc.root.first */ VALUE ruby_xml_xpath_context_node_set(VALUE self, VALUE node) {
Register the specified namespace URI with the specified prefix in this context.
context.register_namespace('xi', 'http://www.w3.org/2001/XInclude')
/* * call-seq: * context.register_namespace(prefix, uri) -> (true|false) * * Register the specified namespace URI with the specified prefix * in this context. * context.register_namespace('xi', 'http://www.w3.org/2001/XInclude') */ VALUE ruby_xml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri) {
Register the specified namespaces in this context.
context.register_namespaces('xi:http://www.w3.org/2001/XInclude') context.register_namespaces(['xlink:http://www.w3.org/1999/xlink', 'xi:http://www.w3.org/2001/XInclude') context.register_namespaces('xlink' => 'http://www.w3.org/1999/xlink', 'xi' => 'http://www.w3.org/2001/XInclude')
/* * call-seq: * context.register_namespaces(["prefix:uri"]) -> self * * Register the specified namespaces in this context. * * context.register_namespaces('xi:http://www.w3.org/2001/XInclude') * context.register_namespaces(['xlink:http://www.w3.org/1999/xlink', * 'xi:http://www.w3.org/2001/XInclude') * context.register_namespaces('xlink' => 'http://www.w3.org/1999/xlink', * 'xi' => 'http://www.w3.org/2001/XInclude') */ VALUE ruby_xml_xpath_context_register_namespaces(VALUE self, VALUE nslist) {
Helper method to read in namespaces defined on a node.
doc = XML::Document.string('<header><first>hi</first></header>') context = XPath::Context.new(doc) context.register_namespaces_from_node(doc.root)
/* call-seq: * context.register_namespaces_from_node(node) -> self * * Helper method to read in namespaces defined on a node. * * doc = XML::Document.string('<header><first>hi</first></header>') * context = XPath::Context.new(doc) * context.register_namespaces_from_node(doc.root) */ VALUE ruby_xml_xpath_context_register_namespaces_from_node(VALUE self, VALUE node) {