Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
2263:ff881b857c98 | 2264:49580a13f71e |
---|---|
91 function stanza_mt:add_child(child) | 91 function stanza_mt:add_child(child) |
92 (self.last_add[#self.last_add] or self):add_direct_child(child); | 92 (self.last_add[#self.last_add] or self):add_direct_child(child); |
93 return self; | 93 return self; |
94 end | 94 end |
95 | 95 |
96 function stanza_mt:get_child(name, xmlns) | |
97 for _, child in ipairs(self.tags) do | |
98 if (not name or child.name == name) | |
99 and ((not xmlns and self.attr.xmlns == child.attr.xmlns) | |
100 or child.attr.xmlns == xmlns) then | |
101 | |
102 return child; | |
103 end | |
104 end | |
105 end | |
106 | |
96 function stanza_mt:child_with_name(name) | 107 function stanza_mt:child_with_name(name) |
97 for _, child in ipairs(self.tags) do | 108 for _, child in ipairs(self.tags) do |
98 if child.name == name then return child; end | 109 if child.name == name then return child; end |
99 end | 110 end |
100 end | 111 end |