util.stanza: Add stanza:get_child(name, xmlns) to find a child tag given a name/xmlns
authorMatthew Wild <mwild1@gmail.com>
Mon, 30 Nov 2009 16:39:27 +0000
changeset 2264 49580a13f71e
parent 2263 ff881b857c98
child 2265 7fe644057dc2
util.stanza: Add stanza:get_child(name, xmlns) to find a child tag given a name/xmlns
util/stanza.lua
--- a/util/stanza.lua	Sun Nov 29 18:30:33 2009 +0500
+++ b/util/stanza.lua	Mon Nov 30 16:39:27 2009 +0000
@@ -93,6 +93,17 @@
 	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