Mercurial > prosody-hg
comparison util/stanza.lua @ 4132:ccc16434dbe2
util.stanza: Add get_child_text() method to get the text of the specified child element (get_child() + get_text() rolled into one step)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 31 Jan 2011 13:05:49 +0000 |
| parents | aa6ca3a7b940 |
| children | 19f2830fbe02 |
comparison
equal
deleted
inserted
replaced
| 4130:c3508071af47 | 4132:ccc16434dbe2 |
|---|---|
| 106 return child; | 106 return child; |
| 107 end | 107 end |
| 108 end | 108 end |
| 109 end | 109 end |
| 110 | 110 |
| 111 function stanza_mt:get_child_text(name, xmlns) | |
| 112 local tag = self:get_child(name, xmlns); | |
| 113 if tag then | |
| 114 return tag:get_text(); | |
| 115 end | |
| 116 return nil; | |
| 117 end | |
| 118 | |
| 111 function stanza_mt:child_with_name(name) | 119 function stanza_mt:child_with_name(name) |
| 112 for _, child in ipairs(self.tags) do | 120 for _, child in ipairs(self.tags) do |
| 113 if child.name == name then return child; end | 121 if child.name == name then return child; end |
| 114 end | 122 end |
| 115 end | 123 end |
