tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r1053823 - /tuscany/sca-cpp/trunk/modules/js/htdocs/xmlutil.js
Date Thu, 30 Dec 2010 08:52:48 GMT
Author: jsdelfino
Date: Thu Dec 30 08:52:48 2010
New Revision: 1053823

URL: http://svn.apache.org/viewvc?rev=1053823&view=rev
Log:
Make XML serialization logic portable across browsers.

Modified:
    tuscany/sca-cpp/trunk/modules/js/htdocs/xmlutil.js

Modified: tuscany/sca-cpp/trunk/modules/js/htdocs/xmlutil.js
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/js/htdocs/xmlutil.js?rev=1053823&r1=1053822&r2=1053823&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/js/htdocs/xmlutil.js (original)
+++ tuscany/sca-cpp/trunk/modules/js/htdocs/xmlutil.js Thu Dec 30 08:52:48 2010
@@ -130,9 +130,6 @@ function readXML(l) {
 }
 
 /**
- * Make an XML document.
- */
-/**
  * Return a list of strings representing an XML document.
  */
 function writeXMLDocument(doc) {
@@ -153,27 +150,49 @@ function expandElementValues(n, l) {
 function writeList(l, node, doc) {
     if (isNil(l))
         return node;
+
     var token = car(l);
     if (isTaggedList(token, attribute)) {
         node.setAttribute(attributeName(token).substring(1), '' + attributeValue(token));
+
     } else if (isTaggedList(token, element)) {
+
+        function mkelem(tok, doc) {
+            function xmlns(l) {
+                if (isNil(l))
+                    return null;
+                var t = car(l);
+                if (isTaggedList(t, attribute)) {
+                    if (attributeName(t).substring(1) == 'xmlns')
+                        return attributeValue(t);
+                }
+                return xmlns(cdr(l));
+            }
+
+            var ns = xmlns(elementChildren(tok));
+            if (ns == null || !doc.createElementNS)
+                return doc.createElement(elementName(tok).substring(1));
+            return doc.createElementNS(ns, elementName(tok).substring(1));
+        }
+
         if (elementHasValue(token)) {
             var v = elementValue(token);
             if (isList(v)) {
                 var e = expandElementValues(elementName(token), v);
                 writeList(e, node, doc);
             } else {
-                var child = doc.createElement(elementName(token).substring(1));
+                var child = mkelem(token, doc);
                 writeList(elementChildren(token), child, doc);
                 node.appendChild(child);
             }
         } else {
-            var child = doc.createElement(elementName(token).substring(1));
+            var child = mkelem(token, doc);
             writeList(elementChildren(token), child, doc);
             node.appendChild(child);
         }
     } else
         node.appendChild(doc.createTextNode('' + token));
+
     writeList(cdr(l), node, doc);
     return node;
 }



Mime
View raw message