# Manually Creating Documents
Besides being able to parse documents, Oga also allows you to create documents
manually. This can be useful if you want to dynamically generate XML/HTML.
Documents can be greated in two ways:
1. Full blown documents (using {Oga::XML::Document})
2. XML fragments (using just {Oga::XML::Element} and the likes)
For example, lets create a document with a specific encoding and a single
element:
xml_decl = Oga::XML::XmlDeclaration.new(:encoding => 'UTF-16')
document = Oga::XML::Document.new(:xml_declaration => xml_decl)
element = Oga::XML::Element.new(:name => 'example')
document.children << element
If you now serialize this back to XML (by calling `document.to_xml`) you'd get
the following XML:
Hello
" Special characters such as `&` and `<` are escaped automatically when calling {Oga::XML::Element#to_xml}.