Module: Ronin::Support::Web::XML

Defined in:
lib/ronin/support/web/xml.rb,
lib/ronin/support/web/xml/mixin.rb

Overview

XML helper methods.

Defined Under Namespace

Modules: Mixin

Class Method Summary collapse

Class Method Details

.build { ... } ⇒ Nokogiri::XML::Builder

Creates a new Nokogiri::XML::Builder.

Examples:

XML.build do
  root {
    foo(id: 'bar')
  }
end

Yields:

  • [] The block that will be used to construct the XML document.

Returns:

  • (Nokogiri::XML::Builder)

    The new XML builder object.

See Also:



104
105
106
# File 'lib/ronin/support/web/xml.rb', line 104

def self.build(&block)
  Nokogiri::XML::Builder.new(&block)
end

.open(path) {|doc| ... } ⇒ Nokogiri::XML::Document

Opens an XML file.

Examples:

doc = XML.open('data.xml')
# => #<Nokogiri::XML::Document:...>

Parameters:

  • path (String)

    The path to the XML file.

Yields:

  • (doc)

    If a block is given, it will be passed the newly created document object.

Yield Parameters:

  • doc (Nokogiri::XML::Document)

    The new XML document object.

Returns:

  • (Nokogiri::XML::Document)

    The parsed XML file.



78
79
80
81
82
# File 'lib/ronin/support/web/xml.rb', line 78

def self.open(path)
  doc = Nokogiri::XML(File.open(path))
  yield doc if block_given?
  return doc
end

.parse(xml) {|doc| ... } ⇒ Nokogiri::XML::Document

Parses the body of a document into a HTML document object.

Parameters:

  • xml (String, IO)

    The XML to parse.

Yields:

  • (doc)

    If a block is given, it will be passed the newly created document object.

Yield Parameters:

  • doc (Nokogiri::XML::Document)

    The new XML document object.

Returns:

  • (Nokogiri::XML::Document)

    The new HTML document object.

See Also:



50
51
52
53
54
# File 'lib/ronin/support/web/xml.rb', line 50

def self.parse(xml)
  doc = Nokogiri::XML.parse(xml)
  yield doc if block_given?
  return doc
end