Converting plain text (string) to XML format ?

Well. I’ve seen that corrupt big tables before.  I strongly suggest you use JSON over XML.  

It should be as simple as replacing the XML encode step with a call to json.encode(), then save that to a file or encrypt it.

If it helps at all, here is a sample with my own library of JSON save/load features:

http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/03/json.zip

You can upgrade this by modifying my table extensions to incorporate encryption and you’ll be golden.

Here is the same example, modified to incorporate a simple (not efficient) encryption process:

http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/03/easy_crypt_json.zip

TIP - Even if you don’t want to convert to JSON, you can use my encryption code (see ssk_core/security.json)  and that should be less likely to corrupt the encoded XML. (My guess is the encryption you’re doing is corrupting some specific characters.  My code handles that safely with a fallback case for characters it doesn’t have in its encode/decode dictionary.)

Here is an example of just the security code in use:

http://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015%20Answer%20Packs/8_August/answers/secureStorage

-Ed

I’m going to jump on the JSON bandwagon here. If you have a function that you are using to load your file and a function to save your file then I recommend you read this tutorial:

https://coronalabs.com/blog/2014/10/14/tutorial-saving-and-loading-lua-tables-with-json/

Lua tables convert to JSON very naturally. XML takes work. In XML you have tags that wrap values, so your tag could be a key and the data inside the tags, the value. But XML also supports key-value attributes. This doesn’t map well to Lua tables. The xml.lua you are using works well on most XML files, but I’m sure along the way, you might find problems with.

But all this said, if you’re just saving tables and loading tables, you don’t need to know XML or JSON. You just need to let the functions work for you. But since XML produces Lua tables with child members (to handle those attributes), JSON is much more natural.

json.encode(yourLuaTable) produces a string. You don’t care how that string is formatted or what’s in it. You know that json.decode(encodedString) will return the original Lua table to you. In your case since you want to encrypt it, take the string output by json.encode, run it through the openSSL encrypt function and write that data out.  When ready read that data into a lua string, pass it through the openSSL decrypt function and you should be back to your original JSON string and you then decode it back to your Lua table.

This is the least path to entry. @roaminggamer’s library is good tool to use.

Rob

Roger that to everything Rob said w/ one addition.  The openSSL is much more secure than my roll-your-own solution.  I merely included this for you to see it isn’t too hard to make something like that on your own.  Call it ‘educational’.

Cheers,

Ed