module OpenvasCli::XmlAddin::ClassMethods

Public Instance Methods

extract_value_from(x_str, n) click to toggle source

Helper method to extract a value from a Nokogiri::XML::Node object. If the xpath provided contains an @, then the method assumes that the value resides in an attribute, otherwise it pulls the text of the last text node.

# File lib/openvas-cli/xml_addin.rb, line 11
def extract_value_from(x_str, n)
  ret = ""
  if x_str =~ /@/
    ret = n.at_xpath(x_str).value  if n.at_xpath(x_str)
  else
    tn =  n.at_xpath(x_str)
    if tn
      if tn.children.count > 0
        tn.children.each { |tnc|
          if tnc.text?
            ret = tnc.text
          end
        }
      else
        ret = tn.text
      end
    end
  end
  
  ret
end