Changeset

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
parents 2263:ff881b857c98
children 2265:7fe644057dc2
files util/stanza.lua
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
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