Changeset

8998:6bddc90eeb27

util.stanza: Add method for removing all children with a specific name, xmlns
author Kim Alvefur <zash@zash.se>
date Sun, 08 Jul 2018 16:48:59 +0200
parents 8991:37ebcc7c6768
children 8999:a2a4c225a3f8 9066:af97ecd00734
files util/stanza.lua
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/util/stanza.lua	Sat Jul 07 20:57:20 2018 +0200
+++ b/util/stanza.lua	Sun Jul 08 16:48:59 2018 +0200
@@ -97,6 +97,16 @@
 	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)