Changeset

2822:511dfd88e14c

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
parents 2821:c0981e104abc
children 2823:b634741acbd0
files util/stanza.lua
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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