Method: Nokogiri::XML::Node#content!

Defined in:
lib/ryoba/nokogiri/xml/node.rb

#content!String Also known as: inner_text!, text!

Equivalent to .content.strip, but raises an error if the result is an empty string.

Examples:

xml = Nokogiri::XML(<<-XML)
  <body>
    <h1>
      Headline 1
    </h1>
    <h2> Headline 2 </h2>
    <h3> </h3>
  </body>
XML

xml.at("h1").content!  # == "Headline 1"
xml.at("h2").content!  # == "Headline 2"
xml.at("h3").content!  # raise error

Returns:

  • (String)

Raises:



52
53
54
55
56
57
58
# File 'lib/ryoba/nokogiri/xml/node.rb', line 52

def content!
  result = self.content.strip
  if result.empty?
    raise Ryoba::Error.new("No text in:\n#{self.to_html}")
  end
  result
end