Class: Nokogiri::XML::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/xliff/xml_extensions.rb

Overview

Helpers for operating on XML Elements

Instance Method Summary collapse

Instance Method Details

#add_leaf_node(element:, content:) ⇒ Void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds a simple Text Node as a child element

Examples:

Look up an existing file

# To Generate <text>Hello World</text>:
xml.add_leaf_node(element: 'text', content: 'Hello World')

Parameters:

  • element (String)

    The XML tag name to use.

  • content (String)

    The text contents of the XML tag.

Returns:

  • (Void)


18
19
20
21
22
# File 'lib/xliff/xml_extensions.rb', line 18

def add_leaf_node(element:, content:)
  node = document.create_element(element)
  node.content = content
  add_child(node)
end