XML/DOM serialization: Difference between revisions

m
→‎{{header|Ruby}}: update output formatting
m (→‎{{header|Ruby}}: add libheader)
m (→‎{{header|Ruby}}: update output formatting)
Line 231:
require("rexml/document")
include REXML
(xmldoc = Document.new) << XMLDecl.new
root =xml doc.add_element('root')
element = root.add_element('element')
element.add_text('Some text here')
 
puts xml.to_s(0)
# save to a string
</lang>
# (the first argument to write() needs an object that understands "<<")
serialized = String.new
doc.write(serialized, 4)
puts serialized</lang>
 
produces
<pre><?xml version='1.0'?>
<root>
<element>
Some text here
</element>
</root></pre>
 
=={{header|Tcl}}==
Anonymous user