From 759fe72f49e08114f36d880e60e64e77781e4c59 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 8 Jul 2018 16:48:59 +0200 Subject: util.stanza: Add method for removing all children with a specific name, xmlns --- util/stanza.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'util') diff --git a/util/stanza.lua b/util/stanza.lua index 2191fa8e..07365144 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -97,6 +97,16 @@ function stanza_mt:add_child(child) return self; end +function stanza_mt:remove_children(name, xmlns) + xmlns = xmlns or self.attr.xmlns; + return self:maptags(function (tag) + if (not name or tag.name == name) and tag.attr.xmlns == xmlns then + return nil; + end + return tag; + end); +end + function stanza_mt:get_child(name, xmlns) for _, child in ipairs(self.tags) do if (not name or child.name == name) -- cgit v1.2.3