Diff

util/stanza.lua @ 2264:49580a13f71e

util.stanza: Add stanza:get_child(name, xmlns) to find a child tag given a name/xmlns
author Matthew Wild <mwild1@gmail.com>
date Mon, 30 Nov 2009 16:39:27 +0000
parent 2077:e33658f6052c
child 2482:a1570e371258
child 2848:b2f367f16eb8
line wrap: on
line diff
--- 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