Module: Nexpose::XMLUtils

Included in:
APIRequest, Connection, DiscoveryConnection
Defined in:
lib/nexpose/util.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.success?(xml_string) ⇒ Boolean

Check a typical Nexpose XML response for success. Typically, the root element has a ‘success’ attribute, and its value is ‘1’ if the call succeeded.

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/nexpose/util.rb', line 32

def self.success?(xml_string)
  xml = ::REXML::Document.new(xml_string.to_s)
  success = ::REXML::XPath.first(xml, '//@success')
  !success.nil? && success.value.to_i == 1
end

Instance Method Details

#make_xml(name, opts = {}, data = '', append_session_id = true) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nexpose/util.rb', line 13

def make_xml(name, opts = {}, data = '', append_session_id = true)
  xml = REXML::Element.new(name)
  if @session_id && append_session_id
    xml.attributes['session-id'] = @session_id
  end

  opts.keys.each do |k|
    xml.attributes[k] = "#{opts[k]}" unless opts[k].nil?
  end

  xml.text = data

  xml
end

#parse_xml(xml) ⇒ Object



9
10
11
# File 'lib/nexpose/util.rb', line 9

def parse_xml(xml)
  ::REXML::Document.new(xml.to_s)
end