I actually made this a while back, but finally decided to open-source it.
This returns a table containing two items - a dictionary of the XML as a Lua dictionary, and an indexed table of the elements in order for looping purposes.
Example Return Value
Input
print(XMLDecode([[
<pizza>
<sauce>Tomato</sauce>
<cheese amount="extra">Mozzarella</cheese>
<meat>Pepperoni</meat>
</pizza>
]]))
Output
{
["dictionary"] = {
["pizza1"] = {
["ATTRIBUTES"] = {},
["_parent"] = "*** cycle table reference detected ***",
["cheese1"] = {
["ATTRIBUTES"] = {
["amount"] = "extra"
},
["_parent"] = "*** cycle table reference detected ***",
["innerText"] = "Mozzarella"
},
["innerText"] = "",
["meat1"] = {
["ATTRIBUTES"] = {},
["_parent"] = "*** cycle table reference detected ***",
["innerText"] = "Pepperoni"
},
["sauce1"] = {
["ATTRIBUTES"] = {},
["_parent"] = "*** cycle table reference detected ***",
["innerText"] = "Tomato"
}
}
},
["indexedTable"] = {
[1] = "pizza1",
[2] = "sauce1",
[3] = "cheese1",
[4] = "meat1"
}
}
Module Link:
GitHub Gist:
xmldecode.lua
type table = {any}
type dict = {[string|boolean]: any}
local specialTags, doNotNeedClosingTag = {}, {}
local find
find = function(originalTable, findValue)
for index, wrappedTable in pairs(originalTable) do
if wrappedTable == findValue then
return wrappedTable
This file has been truncated. show original
9 Likes
D0RYU
(nici)
September 3, 2021, 10:30pm
#2
this is very nice, not sure what I would use this for though
You could theoretically use this to decode rbxmx/rbxlx files in plugins.
Yeah! That would be so cool if plugins could open models and possible do something with them!.
Can you add an Encode so this can become a Codec?
and have you done rigorous testing to make sure it doesn’t fail?
I recommend using TestEz for this
anyways thanks for opening sourcing this!
2 Likes
I’ll work on it, but this was mostly for plugin usage for decoding and breaking down XML files.
I have done testing, yes, and I’ve only found in certain cases that element values get broken down.
1 Like
You can already do that by dragging the .rbxm of the plugin (located in C:\Users\USERNAME\AppData\Local\Roblox\USER_ID\InstalledPlugins\PLUGIN_ID\LATEST_PLUGIN_VERSION/Plugin
) into the studio viewport.
2 Likes
this is cool but I cant think of a use for it. If someone wants to dynamically create instances with code Roact is a better and overall cleaner experience.
Realirist
(Realirist)
December 19, 2024, 6:03pm
#9
I made an instance to xml encoder, not sure if that’s what you’re referring to though