(function(exports){
    var jsdomParseXML = function (text) {
        var parseXmlString = require('deltajs').xmlToDom.parseXmlString;
        return parseXmlString(text);
    }

    var libxmljsParseXml = function (text) {
        var libxmljs = require('libxmljs');
        return libxmljs.parseXmlString(text);
    }

    var browserParseXML = function (text) {
        var xmlParser;
        var xmlDoc;

        if (window.DOMParser) {
            xmlParser = new DOMParser();
            xmlDoc = xmlParser.parseFromString(text,"text/xml");
        }
        else {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async="false";
            xmlDoc.loadXML(text);
        }

        return xmlDoc;
    }

    var parseXML = (typeof window === 'undefined' ? jsdomParseXML : browserParseXML);

    exports.testParseSimpleXML = function(test) {
        var doc = parseXML('<hello-world>');
        test.equals(doc.firstChild.nodeName, 'hello-world');
        test.done();
    }

    exports.testParseSimpleXMLDefaultNS = function(test) {
        var doc = parseXML('<hello xmlns="http://example.com/schema"><world creator="slartibartfast"/></hello>');
        test.equals(doc.firstChild.nodeName, 'hello');
        test.equals(doc.firstChild.namespaceURI, 'http://example.com/schema');

        test.equals(doc.firstChild.firstChild.nodeName, 'world');
        test.equals(doc.firstChild.firstChild.namespaceURI, 'http://example.com/schema');

        test.done();
    }

})(typeof exports === 'undefined' ? (this.domimplTest={}) : exports);

@@ -21,21 +21,22 @@
     var 
-jsdom
+nodejs
 ParseXML
@@ -185,24 +185,23 @@
 var 
-libxmljs
+browser
 ParseX
-ml
+ML
  = f
@@ -229,216 +229,387 @@
     
-var libxmljs = require('libxmljs');%0A        return libxmljs.parseXmlString(text);%0A    %7D%0A%0A    var browserParseXML = function (text) %7B%0A        var xmlParser;%0A        var xmlDoc;%0A%0A        if (window.DOM
+// IE9 (Chakra): http://msdn.microsoft.com/en-us/library/ff975124(v=vs.85).aspx%0A        // No support for IE %3C 9 (not falling back to ActiveX Component).%0A        // FF (Gecko): https://developer.mozilla.org/en/DOM/DOMParser%0A        // No official documentation for WebKit (Safari, Chromium, Konqueror)%0A        // and Opera but recent versions of these browsers provide Dom
 Parser
-) %7B
+.
 %0A   
@@ -609,27 +609,27 @@
 er.%0A        
-   
+var
  xmlParser =
@@ -646,35 +646,35 @@
 rser();%0A        
-   
+var
  xmlDoc = xmlPar
@@ -711,24 +711,25 @@
 /xml%22);%0A
+%0A
         
 %7D%0A      
@@ -724,185 +724,603 @@
     
-%7D
+return xmlDoc;
 %0A    
+%7D%0A%0A
     
-else %7B%0A            xmlDoc = new ActiveXObject(%22Microsoft.XMLDOM%22);%0A            xmlDoc.async=%22false%22;%0A            xmlDoc.loadXML(text);%0A        %7D%0A%0A        return xmlD
+var nodejsSerializeXML = function (doc) %7B%0A        // FIXME%0A    %7D%0A%0A    var browserSerializeXML = function (doc) %7B%0A        // IE9 (Chakra): http://msdn.microsoft.com/en-us/library/ff975124(v=vs.85).aspx%0A        // No support for IE %3C 9%0A        // FF (Gecko): https://developer.mozilla.org/en/XMLSerializer%0A        // No official documentation for WebKit (Safari, Chromium, Konqueror)%0A        // and Opera but recent versions of these browsers provide%0A        // XMLSerializer.%0A        var serializer = new XMLSerializer();%0A        return serializer.serializeToString(d
 oc
+)
 ;%0A  
@@ -1380,13 +1380,14 @@
 ' ? 
-jsdom
+nodejs
 Pars
@@ -1408,24 +1408,124 @@
 ParseXML);%0A%0A
+    var serializeXML = (typeof window === 'undefined' ? nodejsSerializeXML : browserSerializeXML);%0A%0A
     exports.
@@ -1602,16 +1602,17 @@
 lo-world
+/
 %3E');%0A   
@@ -2190,16 +2190,268 @@
 %0A    %7D%0A%0A
+    exports.testSimpleRoundtrip = function(test) %7B%0A        var origText = '%3Chello-world/%3E'%0A        var doc = parseXML(origText);%0A        var serializedText = serializeXML(doc);%0A        test.equals(serializedText, origText);%0A        test.done();%0A    %7D%0A%0A
 %7D)(typeo

Test case for XML-DOM roundtriping. Test passes in browsers but not in CLI/node.js environment