util.stanza, util.xml, util.xmppstream: Add support for tracking defined namespaces...
[prosody.git] / util / xml.lua
index 733d821ad7c8b87dc93d7e4a0b3ab2cfa030fd85..9e12f0dff1b6856cf94a798d2291ead3c223fea9 100644 (file)
@@ -14,6 +14,17 @@ local parse_xml = (function()
                --luacheck: ignore 212/self
                local handler = {};
                local stanza = st.stanza("root");
+               local namespaces = {}
+               function handler:StartNamespaceDecl(prefix, url)
+                       if prefix ~= nil then
+                               namespaces[prefix] = url
+                       end
+               end
+               function handler:EndNamespaceDecl(prefix)
+                       if prefix ~= nil then
+                               namespaces[prefix] = nil
+                       end
+               end
                function handler:StartElement(tagname, attr)
                        local curr_ns,name = tagname:match(ns_pattern);
                        if name == "" then
@@ -34,7 +45,11 @@ local parse_xml = (function()
                                        end
                                end
                        end
-                       stanza:tag(name, attr);
+                       local n = {}
+                       for prefix, url in pairs(namespaces) do
+                               n[prefix] = url
+                       end
+                       stanza:tag(name, attr, n);
                end
                function handler:CharacterData(data)
                        stanza:text(data);