summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-12-30 08:52:48 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-12-30 08:52:48 +0000
commit220c8771ec8948ef80d115e828ccd7bf28126bcc (patch)
tree5a77866edc5dba64e21678dfc3c5bcd64ea3f873
parent910ecec91d3de8d43eee9eef9201dd3fb1e00060 (diff)
Make XML serialization logic portable across browsers.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1053823 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--sca-cpp/trunk/modules/js/htdocs/xmlutil.js29
1 files changed, 24 insertions, 5 deletions
diff --git a/sca-cpp/trunk/modules/js/htdocs/xmlutil.js b/sca-cpp/trunk/modules/js/htdocs/xmlutil.js
index 1bec45f9b9..0edaf400af 100644
--- a/sca-cpp/trunk/modules/js/htdocs/xmlutil.js
+++ b/sca-cpp/trunk/modules/js/htdocs/xmlutil.js
@@ -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;
}