Jump to content

problem with xmlCreateChild overwriting old ones


syrasia

Recommended Posts

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 by syrasia
Link to comment
  • 5 weeks later...

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 by syrasia
Link to comment

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.^_^

  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...