XML/DOM serialization

From Rosetta Code

lorazepam online ultram online kyocera ringtones alprazolam online free alltel ringtones ambien online cheap vicodin free motorola ringtones free sony ericsson ringtones free punk ringtones buy viagra phentermine xanax online buy ultram cheap valium free cingular ringtones buy adipex order cyclobenzaprine cheap propecia cheap tenuate cheap carisoprodol cheap ultracet pharmacy online online wwe ringtones cheap diazepam cheap xenical free nokia ringtones free qwest ringtones zanaflex online cheap diazepam verizon ringtones motorola ringtones lortab online buy prozac free ericsson ringtones but ortho cheap cyclobenzaprine celexa online free ringtones phentermine online cool ringtones prozac online free qwest ringtones cialis online sprint ringtones nexium online free real ringtones free sagem ringtones tracfone ringtones free nokia ringtones punk ringtones free mp3 ringtones free sony ringtones ativan online but hgh midi ringtones alltel ringtones cheap flexeril sony ericsson ringtones free motorola ringtones vicodin online free tracfone ringtones soma online cheap levitra motorola ringtones didrex online cheap sildenafil pharmacy online online cheap zoloft order hydrocodone free sony ringtones free cingular ringtones online viagra paxil online buy ambien lortab online hydrocodone online cheap vigrx cheap ativan buy hgh cheap sildenafil buy viagra buy ortho free nextel ringtones lisinopril free funny ringtones sony ericsson ringtones vicodin online but hydrocodone cheap ativan free mono ringtones clonazepam online levitra free sprint ringtones cheap cialis free sony ringtones levitra online zanaflex online but phentermine cheap celexa ultracet online free wwe ringtones sharp ringtones norco online soma ultracet online cingular ringtones adipex online xenical online cheap albuterol cheap tenuate ortho online music ringtones free sagem ringtones cheap lisinopril meridia online cheap propecia vigrx online diethylpropion online cheap albuterol free mp3 ringtones meridia online free free ringtones cheap ultram soma online cheap lortab cheap sildenafil free nextel ringtones cheap lorazepam funny ringtones diethylpropion online free ringtones free funny ringtones free cingular ringtones cheap soma nokia ringtones clonazepam online cheap zyban clomid online prozac online valium online lisinopril online cheap meridia buy tramadol sharp ringtones midi ringtones flexeril online real ringtones cheap celexa zoloft online nextel ringtones free ericsson ringtones free music ringtones mtv ringtones ultram online valium online viagra online cheap lorazepam cialis online cheap phentermine buy nexium free samsung ringtones cheap norco meridia online sprint ringtones buy rivotril order carisoprodol order carisoprodol buy cyclobenzaprine qwest ringtones qwest ringtones cheap fioricet free verizon ringtones punk ringtones cheap hoodia pharmacy online online tracfone ringtones online tramadol rivotril online cheap tramadol cheap didrex cheap fioricet free music ringtones cheap albuterol nokia ringtones viagra online buy alprazolam xenical online buy pharmacy online funny ringtones cheap zanaflex ericsson ringtones cheap cyclobenzaprine cheap adipex xanax online alltel ringtones free qwest ringtones ultram online free sonyericsson ringtones samsung ringtones

Task
XML/DOM serialization
You are encouraged to solve this task according to the task description, using any language you may know.

Create a simple DOM and having it serialize to:

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

JavaScript

Interpreter: Firefox 2.0

DOM

var doc = document.implementation.createDocument( null, 'root', null );
var root = doc.documentElement;
var element = doc.createElement( 'element' );
root.appendChild( element );
element.appendChild( document.createTextNode('Some text here') );
var xmlString = new XMLSerializer().serializeToString( doc );

E4X

 var xml = <root>
   <element>Some text here</element>
 </root>;
 var xmlString = xml.toXMLString();

E4X — with processing instruction

 XML.ignoreProcessingInstructions = false;
 var xml = <?xml version="1.0"?>  
 <root>
   <element>Some text here</element>
 </root>;
 var xmlString = xml.toXMLString();

Perl

use XML::DOM::BagOfTricks qw(createDocument createTextElement);

my ($doc, $root) = createDocument('root');
$root->appendChild(
    createTextElement($doc, 'element', 'Some text here')
);
print $doc->toString;

PHP

Interpreter: PHP 5

 <?php
 $dom = new DOMDocument();//the constructor also takes the version and char-encoding as it's two respective parameters
 $dom->formatOutput = true;//format the outputted xml
 $root = $dom->createElement('root');
 $element = $dom->createElement('element');
 $element->appendChild($dom->createTextNode('Some text here'));
 $root->appendChild($element);
 $dom->appendChild($root);
 $xmlstring = $dom->saveXML();
 

Python

Interpreter: Python 2.5

 from xml.dom.minidom import getDOMImplementation
 
 dom = getDOMImplementation()
 document = dom.createDocument(None, "root", None)
 
 topElement = document.documentElement
 firstElement = document.createElement("element")
 topElement.appendChild(firstElement)
 textNode = document.createTextNode("Some text here")
 firstElement.appendChild(textNode)
 
 xmlString = document.toprettyxml(" " * 4)

Ruby

 require("rexml/document")
 include REXML
 (xml = Document.new) << XMLDecl.new
 root=xml.add_element('root')
 element=root.add_element('element')
 element.add_text('Some text here')
 puts xml.to_s(0)