diff options
| -rw-r--r-- | lib/xmllib.lua | 47 | 
1 files changed, 46 insertions, 1 deletions
| diff --git a/lib/xmllib.lua b/lib/xmllib.lua index 47eed9b..be76f5e 100644 --- a/lib/xmllib.lua +++ b/lib/xmllib.lua @@ -19,7 +19,7 @@   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   */ -/* $Id: xmllib.lua,v 1.16 2007-07-27 10:05:52 pixel Exp $ */ +/* $Id: xmllib.lua,v 1.17 2007-08-06 14:59:45 pixel Exp $ */  ]]-- @@ -297,6 +297,51 @@ function NewXmlMarkup()      return r  end +function get_xml_section(t, s, norecurs, matches) +    local found, r +     +    function get_xml_section_r(t, s, norecurs, matches) +        local k, v, found, r +        for k, v in pairs(t) do +            if type(v) == "table" then +                if v.name == s then +                    if type(matches) == "table" then +                        local mk, mv +                        found = true +                        for mk, mv in pairs(matches) do +                            if not string.match(v.attr[mk], mv) then +                                found = false +                            end +                        end +                        if not found then +                            if not norecurs then +                                found, r = get_xml_section_r(v, s, norecurs, matches) +                                if found then +                                    return true, r +                                end +                            end +                        else +                            return true, v +                        end +                    else +                        return true, v +                    end +                else +                    if not norecurs then +                        found, r = get_xml_section_r(v, s, norecurs, matches) +                        if found then +                            return true, r +                        end +                    end +                end +            end +        end +        return false, nil +    end +     +    found, r = get_xml_section_r(t, s, norecurs, matches) +    return r +end  --[[ example of use: | 
