Comparison

util/stanza.lua @ 776:89eb9f59993c

util.stanza: Temporary fix for serializing attributes with namespaces
author Matthew Wild <mwild1@gmail.com>
date Wed, 11 Feb 2009 16:09:48 +0000
parent 760:90ce865eebd8
child 829:b01fd698495e
comparison
equal deleted inserted replaced
775:d4b6714fc829 776:89eb9f59993c
10 local t_insert = table.insert; 10 local t_insert = table.insert;
11 local t_concat = table.concat; 11 local t_concat = table.concat;
12 local t_remove = table.remove; 12 local t_remove = table.remove;
13 local t_concat = table.concat; 13 local t_concat = table.concat;
14 local s_format = string.format; 14 local s_format = string.format;
15 local s_match = string.match;
15 local tostring = tostring; 16 local tostring = tostring;
16 local setmetatable = setmetatable; 17 local setmetatable = setmetatable;
17 local pairs = pairs; 18 local pairs = pairs;
18 local ipairs = ipairs; 19 local ipairs = ipairs;
19 local type = type; 20 local type = type;
112 end 113 end
113 114
114 local xml_escape = xml_escape; 115 local xml_escape = xml_escape;
115 116
116 local function dostring(t, buf, self, xml_escape) 117 local function dostring(t, buf, self, xml_escape)
118 local nsid, ns, attrk = 0;
117 t_insert(buf, "<"); 119 t_insert(buf, "<");
118 t_insert(buf, t.name); 120 t_insert(buf, t.name);
119 for k, v in pairs(t.attr) do if type(k) == "string" then 121 for k, v in pairs(t.attr) do if type(k) == "string" then
120 t_insert(buf, " "); 122 t_insert(buf, " ");
121 t_insert(buf, k); 123 ns, attrk = s_match(k, "^([^|]+)|(.+)$");
124 if ns then
125 nsid = (nsid or -1) + 1;
126 t_insert(buf, "xmlns:ns"..nsid);
127 t_insert(buf, "='");
128 t_insert(buf, (xml_escape(tostring(ns))));
129 t_insert(buf, "' ");
130 t_insert(buf, "ns"..nsid..":"..attrk);
131 else
132 t_insert(buf, k);
133 end
122 t_insert(buf, "='"); 134 t_insert(buf, "='");
123 t_insert(buf, (xml_escape(tostring(v)))); 135 t_insert(buf, (xml_escape(tostring(v))));
124 t_insert(buf, "'"); 136 t_insert(buf, "'");
125 end end 137 end end
126 t_insert(buf, ">"); 138 t_insert(buf, ">");