dugasz1 Posted December 11, 2016 Share Posted December 11, 2016 Hello guys! I have a weir issu (or just i don't see what is the problem) So i wanted to write a script which saves a table. But if i call my saveTable method it doesn't load the xml file just create one then overwrite it. And i don't have a clue why... function open( path, version ) --outputDebugString("XML: open called", 1) outputDebugString(rootNode, 1) rootNode = xmlLoadFile(path) outputDebugString(rootNode, 1) if (not rootNode) then outputDebugString(path) rootNode = xmlCreateFile(path, "root") xmlNodeSetAttribute(rootNode, "version", version) xmlCreateChild(rootNode, "tables") outputDebugString("XML: rootNode created", 2) else outputDebugString("XML: rootNode exist",2) local _version = xmlNodeGetAttribute (rootNode, "version") if(tostring(version) ~= _version) then close() outputDebugString("XML: Deleted",2) fileDelete(path) open(path, version) end end end function close( ) xmlSaveFile (rootNode) xmlUnloadFile (rootNode) rootNode = nil outputDebugString("XML: Save and Unload") end function saveTable (path, table, name, version) open(path, version) outputDebugString(rootNode) local tableNode = xmlCreateChildIfNotExist(xmlFindChild(rootNode, "tables", 0), name) outputDebugString(rootNode) saveTableRecursive(path, table, name, tableNode) outputDebugString(rootNode) close() outputDebugString("XML: Table lementve") end function saveTableRecursive (path, table, name, node) for k,v in pairs(table) do local vType = type(v) if (vType == "table") then local newNode = xmlCreateChild(node, k) outputDebugString("XML: Table recurssive") saveTableRecursive (path, v, name, newNode) elseif( (vType == "string") or (vType == "number") or (vType == "boolean") ) then local insertValue = xmlCreateChild(node, k) xmlNodeSetAttribute(insertValue, "type", vType) xmlNodeSetValue(insertValue, tostring(v)) else outputDebugString("XML: Not supported type: "..vType, 1) end end end function xmlCreateChildIfNotExist(parentNode, tagName) local child = xmlFindChild(parentNode, tagName, 0) if not child then child = xmlCreateChild(parentNode, tagName) end return child end local asd = { {x=2, y=5, width=100, height = 200}, {x=44, y=50, width=100, height = 30}, ["test"] = {x=2, y = 5, width = 100, height = false}, } saveTable(":xml/test1.xml", asd, "tesztTable", "1.0") saveTable(":xml/test1.xml", asd, "tesztTable2", "1.0") It fails on line 4. rootNode will be false. What do i do wrong or it is a known issue? PS.: If a got to the file open it and delete a few rows it founds it somewhy. Link to comment
Administrators Lpsd Posted December 11, 2016 Administrators Share Posted December 11, 2016 (edited) Where is the test1.xml file located? Is it in the same resource, inside the xml folder? 26 minutes ago, dugasz1 said: saveTable(":xml/test1.xml", asd, "tesztTable", "1.0") saveTable(":xml/test1.xml", asd, "tesztTable2", "1.0") If so, remove the colons before the filepath Edited December 11, 2016 by LopSided_ Link to comment
dugasz1 Posted December 11, 2016 Author Share Posted December 11, 2016 :xml stands for the path of the xml resource. So the file is in the xml resource's root directory. 2 Link to comment
Administrators Lpsd Posted December 11, 2016 Administrators Share Posted December 11, 2016 9 minutes ago, dugasz1 said: :xml stands for the path of the xml resource. So the file is in the xml resource's root directory. Ah good. Just checking it wasn't that So let me just understand things properly... the rootNode is returning false? Link to comment
dugasz1 Posted December 11, 2016 Author Share Posted December 11, 2016 At line 4 xmlLoadFile return with false. Like it's not found the file but it's there. So the rootNode variable become false. Link to comment
Administrators Lpsd Posted December 11, 2016 Administrators Share Posted December 11, 2016 (edited) 15 minutes ago, dugasz1 said: At line 4 xmlLoadFile return with false. Like it's not found the file but it's there. So the rootNode variable become false. Ah okay, I get you now. I was slightly confused on what the actual problem was. Have you tried including test1.xml in your meta.xml? <config src="xml/test1.xml" type="client" /> Edited December 11, 2016 by LopSided_ Link to comment
dugasz1 Posted December 11, 2016 Author Share Posted December 11, 2016 No but it should work as far as i know. Sometime it loads it. Link to comment
Administrators Lpsd Posted December 11, 2016 Administrators Share Posted December 11, 2016 Mmm, so it works randomly, on and off? and you don't get any kind of error/response when it fails? Link to comment
dugasz1 Posted December 11, 2016 Author Share Posted December 11, 2016 There are no errors. As i mentioned it can't load it but if i edit the content of the test1.xml it load it once, after again can't load it. Link to comment
Administrators Lpsd Posted December 11, 2016 Administrators Share Posted December 11, 2016 (edited) 35 minutes ago, dugasz1 said: There are no errors. As i mentioned it can't load it but if i edit the content of the test1.xml it load it once, after again can't load it. Don't know if you've already crossed this bridge, but have you given ACL rights for "ModifyOtherObjects" on this resource? Also check line 3, 4, 5 in your original reply (shown below) outputDebugString(rootNode, 1) -- rootNode doesn't exist yet rootNode = xmlLoadFile(path) outputDebugString(rootNode, 1) Edited December 11, 2016 by LopSided_ Link to comment
dugasz1 Posted December 11, 2016 Author Share Posted December 11, 2016 I didn't yet but i tried it now. Nothing changed. (I guess it don't needs rights because it works sometimes and the wiki don't say it needs it.) Link to comment
Administrators Lpsd Posted December 11, 2016 Administrators Share Posted December 11, 2016 (edited) Check my updated reply also. This resource should require general.ModifyOtherObjects, because it is editing files outside of its own, in another resource. I'm not sure why you aren't receiving errors about it, I loaded this up and had lots of errors, especially about the ACL Edited December 11, 2016 by LopSided_ Link to comment
dugasz1 Posted December 11, 2016 Author Share Posted December 11, 2016 (edited) When i call first the function i know that the rootNode is nill. But after i call second time the function it is a userdata (I don't know why because i unload it ) It was just for debuging Edit: 9 minutes ago, LopSided_ said: Check my updated reply also. This resource should require general.ModifyOtherObjects, because it is editing files outside of its own, in another resource. I'm not sure why you aren't receiving errors about it, I loaded this up and had lots of errors, especially about the ACL I give them admin rights but still nothing. (It edit it own file yet but i used this kind of path beacause it will be exported. So i guess this is why it don't show error) Edited December 11, 2016 by dugasz1 Link to comment
Administrators Lpsd Posted December 11, 2016 Administrators Share Posted December 11, 2016 (edited) Just spent some time testing everything, got it to work but as you said, "tesztTable2" is overwriting "tesztTable", not appendind to it. I'd just suggest using a library like http://viremo.eludi.net/LuaXML/ - it comes with append functions, so you can just read in data, add to it, and save it again, much easier than what you're using at the moment. Edited December 11, 2016 by LopSided_ Link to comment
dugasz1 Posted December 12, 2016 Author Share Posted December 12, 2016 Thank you i will check it. But i would prefer the built in XML functions so can you please link me the working code? Link to comment
dugasz1 Posted December 13, 2016 Author Share Posted December 13, 2016 Bump. Someone? Link to comment
dugasz1 Posted December 15, 2016 Author Share Posted December 15, 2016 And again. Someone? Link to comment
Tails Posted December 15, 2016 Share Posted December 15, 2016 (edited) You're defining the rootNode globally in open() then you'r nilling it in close(), so it will recreate the file everytime. Just change it to local and remove rootNote = nil in close(). Edit: Or just leave it global and remove the line in close(), OR better, return the rootNode in open() and use it to close it: close(rootNode) Edited December 15, 2016 by Tails 1 Link to comment
dugasz1 Posted December 15, 2016 Author Share Posted December 15, 2016 Thank you, I'm checking it but don't really get it what is hapenning. I took a quick look at it but it fails. I will take a look again on it tomorrow. If i can't manage to do it can we talk a little bit more, and can you explain me again what i'm doing wrong. 1 Link to comment
Tails Posted December 16, 2016 Share Posted December 16, 2016 Sure. Just post the code here, I'll take another look. 1 Link to comment
dugasz1 Posted December 19, 2016 Author Share Posted December 19, 2016 (edited) If someone interested in the anwser: Fuuu... Thanks to @Awang, he find the problem. Node name can't start with numeric... Some XML rules which i didn't know.... (Link) Edited December 19, 2016 by dugasz1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now