util.stanza: Add stanza:get_child(name, xmlns) to find a child tag given a name/xmlns

Mon, 30 Nov 2009 16:39:27 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 30 Nov 2009 16:39:27 +0000
changeset 2822
511dfd88e14c
parent 2821
c0981e104abc
child 2823
b634741acbd0

util.stanza: Add stanza:get_child(name, xmlns) to find a child tag given a name/xmlns

util/stanza.lua file | annotate | diff | comparison | revisions
--- a/util/stanza.lua	Fri Nov 27 17:41:52 2009 +0000
+++ 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

mercurial