Forum: Ruby libxml (XML::Node.content)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aac11966ba9640847450ebeb9d3c18e2?d=identicon&s=25 Kuba Podgorski (kuba)
on 2007-07-23 17:07
Hello all, quick question regarding XML:Node.content method.

Why content is empty for following <code>?


#write
    doc = XML::Document.new()
    doc.root = XML::Node.new('root_node')
    root = doc.root
    root << elem1 = XML::Node.new('elem1')

    elem1['attr1'] = 'Value 1'
    elem1.content  = 'Element 1'

    doc.save('output.xml', true)

#read
    doc = XML::Document.file('output.xml')
    doc.root.find('elem1').each { |e|
puts "#{e}\t text?:#{e.text?}\t content:#{e.content}"
    }

# STDOUT
Element 1       text?:false     content:
This topic is locked and can not be replied to.