Method: Nokogiri::XML::Node#content
- Defined in:
- ext/nokogiri/xml_node.c
#content ⇒ Object 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 <
becomes <
in the returned String.
doc = Nokogiri::XML.fragment("<child>a < 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"
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 |
# File 'ext/nokogiri/xml_node.c', line 770
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;
}
|