You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for asking this question. The short answer is that Nokogiri is functioning as designed, as #content should provide all the text content of all child nodes (recursively).
If you want the text from just the first child node, then you should select just the first child node. Here's one example of how to select the first child that's a text node:
#! /usr/bin/env ruby
require 'nokogiri'
xml = %Q{<text> A additional note: <content ID="ap1">This is a generated Text, just for demo purposes (section 2: Active Problems) </content> </text>}
doc = Nokogiri::XML::Document.parse xml
puts doc.root.children.find {|n| n.text?}
If I try to read the text content of a XML node, I get the the text content of all child elements as well.
Check for example:
<text> A additional note: <content ID="ap1">This is a generated Text, just for demo purposes (section 2: Active Problems) </content> </text>
where the .content or .text message on the text node returns:
A additional note:
This is a generated Text,
just for demo purposes (section 2: Active Problems)
with the child tags removed.
But I expected to get one child element on the node and the text content to be 'A additional note:' only.
The text was updated successfully, but these errors were encountered: