aboutsummaryrefslogtreecommitdiffstats
path: root/util/xml.lua
diff options
context:
space:
mode:
Diffstat (limited to 'util/xml.lua')
-rw-r--r--util/xml.lua24
1 files changed, 23 insertions, 1 deletions
diff --git a/util/xml.lua b/util/xml.lua
index 733d821a..dac3f6fe 100644
--- a/util/xml.lua
+++ b/util/xml.lua
@@ -1,8 +1,11 @@
local st = require "util.stanza";
local lxp = require "lxp";
+local t_insert = table.insert;
+local t_remove = table.remove;
local _ENV = nil;
+-- luacheck: std none
local parse_xml = (function()
local ns_prefixes = {
@@ -14,6 +17,21 @@ local parse_xml = (function()
--luacheck: ignore 212/self
local handler = {};
local stanza = st.stanza("root");
+ local namespaces = {};
+ local prefixes = {};
+ function handler:StartNamespaceDecl(prefix, url)
+ if prefix ~= nil then
+ t_insert(namespaces, url);
+ t_insert(prefixes, prefix);
+ end
+ end
+ function handler:EndNamespaceDecl(prefix)
+ if prefix ~= nil then
+ -- we depend on each StartNamespaceDecl having a paired EndNamespaceDecl
+ t_remove(namespaces);
+ t_remove(prefixes);
+ end
+ end
function handler:StartElement(tagname, attr)
local curr_ns,name = tagname:match(ns_pattern);
if name == "" then
@@ -34,7 +52,11 @@ local parse_xml = (function()
end
end
end
- stanza:tag(name, attr);
+ local n = {}
+ for i=1,#namespaces do
+ n[prefixes[i]] = namespaces[i];
+ end
+ stanza:tag(name, attr, n);
end
function handler:CharacterData(data)
stanza:text(data);