Create a simple DOM and having it serialize to:

 <?xml version="1.0" ?>
 <root>
     <element>
         Some text here
     </element>
 </root>

/* NetRexx */
options replace format comments java crossref symbols nobinary
 
import java.io.StringWriter
import javax.xml.
import org.w3c.dom.
 
class RDOMSerialization public
 
properties private
  domDoc = Document
 
method main(args = String[]) public static
 
  lcl = RDOMSerialization()
  lcl.buildDOMDocument()
  lcl.serializeXML()
 
  return
 
method buildDOMDocument() inheritable
 
  do
    factory = DocumentBuilderFactory.newInstance()
    builder = factory.newDocumentBuilder()
    impl = builder.getDOMImplementation()
    domDoc = impl.createDocument(null, null, null)
    elmt1 = domDoc.createElement("root")
    elmt2 = domDoc.createElement("element")
    elmt2.setTextContent("Some text here")
 
    domDoc.appendChild(elmt1)
    elmt1.appendChild(elmt2)
 
  catch exPC = ParserConfigurationException
    exPC.printStackTrace
  end
 
  return
 
method serializeXML() inheritable
 
  do
    domSrc = DOMSource(domDoc)
    txformer = TransformerFactory.newInstance().newTransformer()
    txformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no")
    txformer.setOutputProperty(OutputKeys.METHOD, "xml")
    txformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8")
    txformer.setOutputProperty(OutputKeys.INDENT, "yes")
    txformer.setOutputProperty(OutputKeys.STANDALONE, "yes")
    txformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2")
 
    sw = StringWriter()
    sr = StreamResult(sw)
 
    txformer.transform(domSrc, sr)
 
    say sw.toString
 
  catch exTC = TransformerConfigurationException
    exTC.printStackTrace
  catch exTF = TransformerFactoryConfigurationError
    exTF.printStackTrace
  catch exTE = TransformerException
    exTE.printStackTrace
  end
 
  return
 