class Object
Public Instance Methods
add_element(name, attributes={})
click to toggle source
# File lib/ruby/nokogiri_ext.rb, line 4 def add_element(name, attributes={}) (prefix, name) = name.split(':') if name.include?(':') node = Nokogiri::XML::Node.new(name, self) attributes.each do |attr, val| node.set_attribute(attr, val) end ns = node.add_namespace_definition(prefix, Ruby::Ods::Manager::NAMESPACES[prefix]) node.namespace = ns self.add_child(node) node end
fetch(xpath)
click to toggle source
# File lib/ruby/nokogiri_ext.rb, line 16 def fetch(xpath) if node = self.xpath(xpath).first return node end return self.add_element(xpath) unless xpath.include?('/') xpath = xpath.split('/') last_path = xpath.pop fetch(xpath.join('/')).fetch(last_path) end