Reading XML in Lua |
Pagoda « Citoyen » 1676454000000
| 0 | ||
Hi All So I have been helping my friend fixing his module, as it stands the problem is fixed but it makes it very inconvenient for him when loading maps. Basically, he is loading Defilante objects into the map via Lua, but doing it one-by-one is difficult. He still has the defilante objects in map XML so I just want to hear from people's experience messing with XML in Lua. After loading the map into a variable, what is the best way to parse that XML, so that each Defilante object can be placed into the map by Lua? Thanks! |
Pagoda « Citoyen » 1676456760000
| 0 | ||
To make my idea clearer, this is the sort of end result I would want: 1 2 3 4 5 6 7 8 9 10 XMLmap = "<xml/><blah><blaha/>...." And it would place all of the Defilante objects into the map when a new round starts, or when the mouse dies. P.S. Forgive me if the Lua code is wrong, this is just an example of how it would work |
Wizardamani0 « Citoyen » 1676461740000
| 0 | ||
Give an example please. |
Pagoda « Citoyen » 1676475960000
| 0 | ||
Wizardamani0 a dit : Hi Wizardman I just want anybody's tips about parsing XML. I imagine it would be like string split as seen in this tutorial: https://www.tutorialspoint.com/how-to-split-a-string-in-lua-programming Is it possible to use that to parse the XML? I just want some tips to deal with it |
Pagoda « Citoyen » 1676477400000
| 0 | ||
Hey I found some people online have written about it in the past so I think I'll follow their advice. I just checked string.gmatch() works within Transformice. |
Bomboffkiler « Citoyen » 1676559360000
| 0 | ||
Considering the XML isn't complex, simple matching with regular expressions works really. Note that Lua's regular expressions don't look like JavaScript ones (JavaScript RegExp is based in Perl). You can parse the XML string more in depth (like, Code Point by Code Point or match by match). |
1 | ||
Dernière modification le 1676748180000 |
Pagoda « Citoyen » 1677085680000
| 0 | ||
Hey guys, thanks for your help. This is the code I created which will parse the Defilante objects. I had trouble with converting it from Regex to the Lua patterns but this works fine 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 xml = "" |