Wikia Developers Wiki

Global Lua Modules/Xml parser

< Global Lua Modules

847pages on
this wiki
Add New Page
Talk0 Share
A module that converts xml files to lua tables. See [1].


Installing modules

To get a brief introduction to lua read the basics page first. On Wikia, one can use modules by either accessing a module remotely or copying all its contents to a Wiki. Modules accessed remotely from dev.wikia are subject to change while 'correctly' copied modules are controlled by a particular wiki.

Using a module "remotely" using Module:Devmodule

Create Module:Devmodule and copy the following code to remotely access modules in dev's repository. See more details in Global Lua Modules/Devmodule.
--[[This imports modules from dev.wikia]]
return require("Dev:Devmodule")

Loading modules remotely from dev.wikia

Create Module:Xml parser in your wiki and add the following code:
--This loads modules directly from
return require("Dev:Xml parser")

Using Module:Xml parser in another wiki

To use modules without depending on dev see this page. Create Template:Xml parser in your wiki and add the following code:
{{#invoke:Xml parser|main}}

Using template in a page

You can use this module in a page using syntax such as:
{{Xml parser|main|arg1|arg2}}
Dev:Codedoc/Procsrc:97: use --% before --@

stack traceback: [C]: in function 'assert' Dev:Codedoc/Procsrc:97: in function 'get_functions' Dev:Codedoc/Procsrc:176: in function <Dev:Codedoc/Procsrc:166> (tail call): ? [C]: in function 'xpcall' Module:Codedoc:33: in function 'createDocs' Module:Lua_install:68: in function <Module:Lua_install:29> (tail call): ? mw.lua:430: in function <mw.lua:425> (tail call): ? [C]: in function 'xpcall' ...ensions/Scribunto/engines/LuaStandalone/MWServer.lua:73: in function 'handleCall' ...ensions/Scribunto/engines/LuaStandalone/MWServer.lua:266: in function 'dispatch' ...ensions/Scribunto/engines/LuaStandalone/MWServer.lua:33: in function 'execute' ...tensions/Scribunto/engines/LuaStandalone/mw_main.lua:7: in main chunk [C]: ?


local xmlStreamParser= require("Module:xml parser")
local libXmlHandler = require("Module:xml handler")
local xmltext =[[<?xml version="1.0" encoding="ISO-8859-1"?>
  <pessoa tipo="F">
--Instantiate the object the states the XML file as a Lua table
local xmlhandler = libXmlHandler.simpleTreeHandler()
--Instantiate the object that parses the XML to a Lua table
local xmlparser = xmlStreamParser.xmlParser(xmlhandler)
--Recursivelly prints the table
--Manually prints the table (once that the XML structure for this example is previously known)
  for k, p in pairs(xmlhandler.root.pessoas.pessoa) do
     mw.log("Nome:", p.nome, "Cidade:", p.cidade, "Tipo:", p._attr.tipo)

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.