summaryrefslogtreecommitdiff
path: root/lib/xmllib.lua
diff options
context:
space:
mode:
authorpixel <pixel>2007-08-06 14:59:45 +0000
committerpixel <pixel>2007-08-06 14:59:45 +0000
commit5621123d7c16be8800e37f3abd6d28151fc386ae (patch)
tree5d4b0cc7b387a1ee663d98a84fb5f77fb88639cf /lib/xmllib.lua
parent0b9a302e5c29cbfe56f16e91fd360a769d257a93 (diff)
Adding "get_xml_section" function.
Diffstat (limited to 'lib/xmllib.lua')
-rw-r--r--lib/xmllib.lua47
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: