Method: Nokogiri::XML::Node#content

Defined in:
ext/nokogiri/xml_node.c

#contentObject Also known as: inner_text, text, to_str

:call-seq:

content() → String
inner_text() → String
text() → String
to_str() → String
Returns

Contents of all the text nodes in this node’s subtree, concatenated together into a single String.

⚠ Note that entities will always be expanded in the returned String.

See related: #inner_html

Example of how entities are handled:

Note that &lt; becomes < in the returned String.

doc = Nokogiri::XML.fragment("<child>a &lt; b</child>")
doc.at_css("child").content
# => "a < b"

Example of how a subtree is handled:

Note that the <span> tags are omitted and only the text node contents are returned, concatenated into a single string.

doc = Nokogiri::XML.fragment("<child><span>first</span> <span>second</span></child>")
doc.at_css("child").content
# => "first second"


756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
# File 'ext/nokogiri/xml_node.c', line 756

static VALUE
rb_xml_node_content(VALUE self)
{
  xmlNodePtr node;
  xmlChar *content;

  Noko_Node_Get_Struct(self, xmlNode, node);

  content = xmlNodeGetContent(node);
  if (content) {
    VALUE rval = NOKOGIRI_STR_NEW2(content);
    xmlFree(content);
    return rval;
  }
  return Qnil;
}