Issue with iterating through child nodes of XML in Ruby -


i want iterate through child nodes of main node of xml in ruby, output not expected.

this xml:

<?xml version="1.0"?> <main>     <sub>       <a></a>       <b></b>     </sub> </main> 

i need iterate through child nodes of "sub":

require 'nokogiri' f = file.open('test.xml') doc = nokogiri::xml(f)  main_node = doc.xpath("//main/sub").first subnode = main_node.children  subnode.each |node|     puts "#{node.name}" end 

i expecting output as:

    b 

but

text text b text 

use noblanks parse option.

http://www.nokogiri.org/tutorials/parsing_an_html_xml_document.html#parse_options

doc = nokogiri::xml(f) |config|   config.noblanks end 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -