Insert Text After Specific XML Tag in Nokogiri
问题 I'd like to create the following XML: <?xml version="1.0"> <foo> <bar/> TEXT GOES HERE </foo> The structure is pretty simple to build with Nokogiri: builder = Nokogiri::XML::Builder.new do |xml| xml.foo { xml.bar {} } end puts builder.to_xml What I can't figure out is how to insert the TEXT GOES HERE string inside <foo> but after <bar/> . Obviously, xml.foo("TEXT GOES HERE") produces the text before <bar> . What am I missing? 回答1: You want the text method: require 'nokogiri' builder =