Closed sigmasoldi3r closed 7 years ago
Hello @sigmasoldi3r
You have some issues in your code.
You are using the handler module without assigning it to a variable. That variable is the one used to access the elements into your XML.
And you don't need to assign the result of x:parse
to a variable t
because x
is already your parser.
You have just to follow the provided examples.
There are also some confusions in your code because your top-level XML element is called root and the table generated after parsing the XML always have an element called root.
This way, in the example below, you have to call handler.root.root.elem[1]
to access the first element tag (notice there is the root
which is always created by xml2lua and inside it, the root
contained in your XML).
require('xml2lua')
local handler = require('xmlhandler/tree')
local parser = xml2lua.parser(handler)
parser:parse([[
<root>
<elem at="hello">hi</elem>
</root>
]])
--Prints the entire table representing the parsed XML
--xml2lua.printable( handler.root.root)
print("elem 1:", handler.root.root.elem[1])
print("elem 1 at:", handler.root.root.elem._attr.at)
Hello there! I'm trying to implement this parser in
Garrysmod
(A game that uses a... uh, a "custom" implementation of Lua, wich is horrible) and the script throws this error in whatever XML string I pass to the parser:Stacktrace
Code
Original code (Moonscript):
Tested code (Lua):
XML Tried
First attempt:
Second (Without headers)
Third (Without attributes)
Even I've tried adding and removing blank and newline charaters of padding, without success.