Software /
code /
prosody
Diff
util/xml.lua @ 6978:30c96a5db360
util.stanza, util.xml, util.xmppstream: Add support for tracking defined namespaces and their prefix (stanza.namespaces), knowing/preserving prefix names is required for some applications (thanks daurnimator)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 08 Dec 2015 23:15:42 +0000 |
parent | 6777:5de6b93d0190 |
child | 7239:c9af793b2d8f |
line wrap: on
line diff
--- a/util/xml.lua Sun Dec 06 02:43:01 2015 +0100 +++ b/util/xml.lua Tue Dec 08 23:15:42 2015 +0000 @@ -14,6 +14,17 @@ --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 @@ 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);