util.stanza: Temporary fix for serializing attributes with namespaces

Wed, 11 Feb 2009 16:09:48 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 11 Feb 2009 16:09:48 +0000
changeset 776
89eb9f59993c
parent 775
d4b6714fc829
child 785
31d5be1371cf

util.stanza: Temporary fix for serializing attributes with namespaces

util/stanza.lua file | annotate | diff | comparison | revisions
--- a/util/stanza.lua	Mon Feb 09 14:24:49 2009 +0000
+++ b/util/stanza.lua	Wed Feb 11 16:09:48 2009 +0000
@@ -12,6 +12,7 @@
 local t_remove      =  table.remove;
 local t_concat      =  table.concat;
 local s_format      = string.format;
+local s_match      = string.match;
 local tostring      =      tostring;
 local setmetatable  =  setmetatable;
 local pairs         =         pairs;
@@ -114,11 +115,22 @@
 local xml_escape = xml_escape;
 
 local function dostring(t, buf, self, xml_escape)
+	local nsid, ns, attrk = 0;
 	t_insert(buf, "<");
 	t_insert(buf, t.name);
 	for k, v in pairs(t.attr) do if type(k) == "string" then
 		t_insert(buf, " ");
-		t_insert(buf, k);
+		ns, attrk = s_match(k, "^([^|]+)|(.+)$");
+		if ns then
+			nsid = (nsid or -1) + 1;
+			t_insert(buf, "xmlns:ns"..nsid);
+			t_insert(buf, "='");
+			t_insert(buf, (xml_escape(tostring(ns))));
+			t_insert(buf, "' ");
+			t_insert(buf, "ns"..nsid..":"..attrk);
+		else
+			t_insert(buf, k);
+		end
 		t_insert(buf, "='");
 		t_insert(buf, (xml_escape(tostring(v))));
 		t_insert(buf, "'");

mercurial