" I want instead of " /> " I want instead of " /> " I want instead of "/>

rexml - How to print empty node with close tag

160 views Asked by At
require 'rexml/document'
str = File.readlines('myxml.xml').join # '<a></a>'
el = REXML::Document.new str
p el.to_s # "<a/>"

I want <a></a> instead of <a />. How can I get this with rexml in ruby?

1

There are 1 answers

1
Aleksei Matiushkin On

Since it’s an XML, the elements got collapsed unless there is a [possibly emply] node nested:

el.root.add_text ''
el.to_s
#⇒ "<a></a>"