From 70c975bfe07e639931a0f6e1e21c4783ac6fa5a1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 30 Nov 2009 16:39:27 +0000 Subject: util.stanza: Add stanza:get_child(name, xmlns) to find a child tag given a name/xmlns --- util/stanza.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'util/stanza.lua') diff --git a/util/stanza.lua b/util/stanza.lua index d295d5cc..8d3b7747 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -93,6 +93,17 @@ function stanza_mt:add_child(child) return self; end +function stanza_mt:get_child(name, xmlns) + for _, child in ipairs(self.tags) do + if (not name or child.name == name) + and ((not xmlns and self.attr.xmlns == child.attr.xmlns) + or child.attr.xmlns == xmlns) then + + return child; + end + end +end + function stanza_mt:child_with_name(name) for _, child in ipairs(self.tags) do if child.name == name then return child; end -- cgit v1.2.3