-local xml_escape = xml_escape;
-
-function stanza_mt.__tostring(t)
- local children_text = "";
- for n, child in ipairs(t) do
- if type(child) == "string" then
- children_text = children_text .. xml_escape(child);
+local function _dostring(t, buf, self, xml_escape)
+ local nsid = 0;
+ local name = t.name
+ t_insert(buf, "<"..name);
+ for k, v in pairs(t.attr) do
+ if s_find(k, "|", 1, true) then
+ local ns, attrk = s_match(k, "^([^|]+)|(.+)$");
+ nsid = nsid + 1;
+ t_insert(buf, " xmlns:ns"..nsid.."='"..xml_escape(ns).."' ".."ns"..nsid..":"..attrk.."='"..xml_escape(v).."'");