Module: VtdXml::Navigation
Instance Method Summary collapse
- #clear_xpath_namespaces ⇒ Object
- #register_namespaces(namespaces) ⇒ Object
- #search(xpath) ⇒ Object
- #xpath(*xpaths) ⇒ Object
Instance Method Details
#clear_xpath_namespaces ⇒ Object
38 39 40 41 42 43 |
# File 'lib/vtd_xml/document.rb', line 38 def clear_xpath_namespaces begin @pilot.clear_xpath_name_spaces() rescue NullPointerException end end |
#register_namespaces(namespaces) ⇒ Object
33 34 35 36 37 |
# File 'lib/vtd_xml/document.rb', line 33 def register_namespaces(namespaces) namespaces.each do |prefix, url| @pilot.declare_xpath_name_space(prefix.to_s, url.to_s) end end |
#search(xpath) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/vtd_xml/document.rb', line 7 def search(xpath) @pilot.select_xpath(xpath) results = [] while (result = @pilot.eval_xpath()) != -1 results << Node.new(result, @navigator, @pilot, @modifier) end results end |
#xpath(*xpaths) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vtd_xml/document.rb', line 18 def xpath(*xpaths) namespaces = Hash === xpaths.last ? xpaths.pop : {} register_namespaces(namespaces) results = xpaths.map { |xpath| search(xpath) } results.flatten! results.compact! results rescue XPathParseException => e raise XPathError, '%s for xpath: %s' % [e., xpaths.inspect] ensure clear_xpath_namespaces end |