DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Adding An XML Declaration To A REXML Document

  • submit to reddit
        Source: <a href="">REXML Tutorial - Home</a> []

REXML will not, by default, write out the XML declaration unless you specifically ask for them. If a document is read that contains an XML declaration, that declaration will be written faithfully. The other way you can tell REXML to write the declaration is to specifically add the declaration:
Adding an XML Declaration to a Document
doc = 
doc.add_element 'foo'
doc.to_s   #-> <foo/>
doc <<
doc.to_s   #-> <?xml version='1.0'?><foo/>