# HG changeset patch # User Matthew Wild # Date 1234368588 0 # Node ID 89eb9f59993ca08e0f0e0a52589d74d095922894 # Parent d4b6714fc82979e87b6523d4b1c9d4fcce9f5c66 util.stanza: Temporary fix for serializing attributes with namespaces diff -r d4b6714fc829 -r 89eb9f59993c util/stanza.lua --- 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, "'");