From 0a8bd35cebf8ee3772e1f9acd5740aea8db65d25 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 11 Feb 2009 16:09:48 +0000 Subject: util.stanza: Temporary fix for serializing attributes with namespaces --- util/stanza.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'util/stanza.lua') diff --git a/util/stanza.lua b/util/stanza.lua index 0b15ceed..1c1cab0e 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -12,6 +12,7 @@ local t_concat = table.concat; 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 @@ end 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, "'"); -- cgit v1.2.3