[vlc-devel] commit: Fix simplexml (still has issues with <bla/> tags) ( Antoine Cellerier )

git version control git at videolan.org
Sun Feb 14 23:29:15 CET 2010


vlc | branch: master | Antoine Cellerier <dionoea at videolan.org> | Sun Feb 14 23:30:31 2010 +0100| [c62856983247568d5c3eb5619c7863d41adc80b7] | committer: Antoine Cellerier 

Fix simplexml (still has issues with <bla/> tags)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c62856983247568d5c3eb5619c7863d41adc80b7
---

 share/lua/intf/modules/common.lua |    4 ++++
 share/lua/modules/simplexml.lua   |   23 +++++++++++++++--------
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/share/lua/intf/modules/common.lua b/share/lua/intf/modules/common.lua
index c02d4e7..1215ab8 100644
--- a/share/lua/intf/modules/common.lua
+++ b/share/lua/intf/modules/common.lua
@@ -54,6 +54,10 @@ end
 -- print a table (recursively)
 function table_print(t,prefix)
     local prefix = prefix or ""
+    if not t then
+        print(prefix.."/!\\ nil")
+        return
+    end
     for a,b in pairs_sorted(t) do
         print(prefix..tostring(a),b)
         if type(b)==type({}) then
diff --git a/share/lua/modules/simplexml.lua b/share/lua/modules/simplexml.lua
index 13d9a0b..e2f6b1f 100644
--- a/share/lua/modules/simplexml.lua
+++ b/share/lua/modules/simplexml.lua
@@ -37,25 +37,32 @@ local function parsexml(stream)
     local parents = {}
     while reader:read() > 0 do
         local nodetype = reader:node_type()
+        --print(nodetype, reader:name())
         if nodetype == 'startelem' then
             local name = reader:name()
-            local node = { name: '', attributes: {}, children: {} }
+            local node = { name= '', attributes= {}, children= {} }
             node.name = name
-            while reader:NextAttr() == 0 do
-                node.attributes[reader:Name()] = reader:Value()
+            while reader:next_attr() == 0 do
+                node.attributes[reader:name()] = reader:value()
             end
             if tree then
-                tree.children[#tree.children] = node
-                parents[#parents] = tree
-                tree = node
+                table.insert(tree.children, node)
+                table.insert(parents, tree)
             end
+            tree = node
         elseif nodetype == 'endelem' then
-            tree = parents[#parents-1]
+            if #parents > 0 then
+                tree = parents[#parents]
+                table.remove(parents)
+            end
         elseif nodetype == 'text' then
-            node.children[#node.children] = reader:Value()
+            table.insert(tree.children, reader:value())
         end
     end
 
+    if #parents > 0 then
+        error("XML parser error/Missing closing tags")
+    end
     return tree
 end
 




More information about the vlc-devel mailing list