Community Forum

Save XML attributes with <![CODE[ tag

Forum Overview >> Scripting

CategoryScripting
Created14.05.2019 01:32


Dan Persson (danpe) 14.05.2019 01:32
Hi,

I'm using XML files in my mod which contains some attributes/tags with arbitrary text. It works just fine to load the XML content if I manually added the <![CODE[ tag in a text editor, the line breaks will be preserved when showing it within the game. However, if I try to write exactly the same string to the XML file using XMLSetString() from within the game, the <![CODE[ will not be present, so next time the game is loaded my text will be without the CODE-tag. Is it somehow possible to generate the CODE-tag using the in-game XML-functions?

Best Regards,
Danne

Gtx | Andy (GtX_Andy) 14.05.2019 03:44
The only way you can add your tags will be to write the XML using 'io class'

local xmlFile = io.open (directoryPath .. "/fileToCreateOrWriteTo.xml", "w")

xmlFile:write('<!-- This is text that will be added to your file -->')

xmlFile:close()
xmlText = nil


Using the above and the lua StringPaterns you will be able to create a complete XML file laid out how you wish ;-)

Regards,
GtX

https://github.com/GtX-Andy


Dan Persson (danpe) 14.05.2019 19:26
Thank you for the quick response! That solution will work just fine for me.

Best Regards,
Danne


Note: Log in to post. Create a new account here.