syrasia Posted November 20, 2016 Share Posted November 20, 2016 (edited) Hi there, I am trying to implement a error system, and i am stuck on the problem, that xmlCreateChild overwrites the old node and so i cant get an error-list. Here is the Code: [lua]--------------------------------------------------Fehler in XML speichern-------------------------------------------------- function registerError( errorType, errorDescription ) local xmlErrorLog = xmlLoadFile( "errorLog.xml" ) if xmlErrorLog == false then xmlErrorLog = xmlCreateFile( "errorLog.xml", "errors" ) end local time = getRealTime( ) -- Die Zeit des Fehlers local timeString = "" .. time["year"]+1900 .. "." .. time["month"]+1 .. "." .. time["monthday"] .. "-" .. time["hour"] .. "." .. time["minute"] .. "." .. time["second"] local xmlNewError = xmlCreateChild( xmlErrorLog, timeString ) xmlNodeSetAttribute( xmlNewError, "type", errorType ) xmlNodeSetAttribute( xmlNewError, "description", errorDescription ) xmlSaveFile( xmlErrorLog ) xmlUnloadFile( xmlErrorLog ) end addEvent( "registerError" ) addEventHandler( "registerError", root, registerError )[/lua] The node should have been the timestamp, as the "new" node needs a new name, but it doesnt work (old nodes get overwriten). Edit: and somehow the [lua] [/lua] code syntax does not work? Sorry for that too! Edited November 20, 2016 by syrasia Link to comment
syrasia Posted November 20, 2016 Author Share Posted November 20, 2016 Okay guys, I found my error in the error script.... I somehow was creating a new xml file every time. Don't ask how, I just done it. After changing the script a bit, it works. Sorry to boter you for nothing. Link to comment
syrasia Posted December 19, 2016 Author Share Posted December 19, 2016 (edited) Alright, and it still overwrites the file. Where is my mistake? xmlErrorLog = nil function systemInit( ) xmlRootNode = xmlLoadFile( "errors.xml" ) if xmlRootNode == false then outputServerLog ( "-----creation of new error file-----" ) xmlRootNode = xmlCreateFile( "errors.xml", "errors" ) end xmlSaveFile( xmlRootNode ) xmlErrorLog = xmlRootNode end addEventHandler( "onResourceStart", getResourceRootElement(), systemInit ) Edited December 19, 2016 by syrasia Link to comment
dugasz1 Posted December 20, 2016 Share Posted December 20, 2016 Maybe you have the same problem what i had. Link If you'r node name start with numeric then it's invalid xml and xmlLoadFile will return false. Link to comment
SheriFF Posted December 20, 2016 Share Posted December 20, 2016 To check if the file exists use this if ( fileExist( "xmlFileName.xml" ) ) then xmlLoadFile( "fileName.xml" ) else xmlCreateFile(...) end Also, Lua( maybie ) doesn't support names starting with a number Link to comment
syrasia Posted December 20, 2016 Author Share Posted December 20, 2016 @dugasz1 I think this may be the soulution, becasue I use the date as the node name. Okay, i will change this then somehow. Link to comment
dugasz1 Posted December 20, 2016 Share Posted December 20, 2016 I just put a prefix before it if first character is numeric. Link to comment
syrasia Posted December 21, 2016 Author Share Posted December 21, 2016 Oh well, after a very long annoying evening, where I tried to fix it (sometimes it still overwrites the file), I decided to swap to sql. I even read it some times, that one shouldn't use xml, as ist slow and not good for data storage, but I was to lazy to get int sql. Surprisingly I got into sql query's logic fast and have to say, well I don't need any xml (at the moment) anymore, so this is more or less solved. Still thank you for your help, friends. 1 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