Jump to content

xml file error


Tigr_2020

Recommended Posts

Hello everyone, Today I encountered an error with the xml file, an error is shown in the debug:

[23-02-25 18:05:30] WARNING: [gameplay]/drag/drag_s.lua:413: Unable to read XML file database.xml @ 'xmlLoadFile' [Line 0: Error document empty.]
[23-02-25 18:05:30] WARNING: [gameplay]/drag/drag_s.lua:440: Unable to read XML file database.xml @ 'xmlLoadFile' [Line 0: Error document empty.]

The database.xml file is empty

Server side:

 

-- CORE
function updateTopTimeDatabase(topTime, vehicleName)
    local playerSerial = source:getSerial()
    local playerName = string.gsub(source:getName(), "#%x%x%x%x%x%x", "")
    local dataFile = nil
    if fileExists("database.xml") then
        dataFile =xmlLoadFile("database.xml")
    else
        dataFile = xmlCreateFile("database.xml", "accounts")
    end
    if (dataFile) then
        local nodesXml = xmlNodeGetChildren(dataFile)
        local isTopTimeAdding = true
        for i, n in ipairs(nodesXml) do
            if xmlNodeGetAttribute(n, "id") == playerSerial then
                if (tonumber(xmlNodeGetAttribute(n, "time")) > topTime) then
                    xmlDestroyNode(n)
                else
                    isTopTimeAdding = false
                end
            end
        end
        if (isTopTimeAdding == true) then
            local xmlNumbers = xmlCreateChild(dataFile, "data")
            xmlNodeSetAttribute(xmlNumbers, "id", tostring(playerSerial))
            xmlNodeSetAttribute(xmlNumbers, "name", playerName)
            xmlNodeSetAttribute(xmlNumbers, "vehicle", vehicleName)
            xmlNodeSetAttribute(xmlNumbers, "time", topTime)
        end
        xmlSaveFile(dataFile)
        xmlUnloadFile(dataFile)
        dataFile = nil
    end
    dataFile =xmlLoadFile("database.xml")
    if (dataFile) then
        local nodesXml = xmlNodeGetChildren(dataFile)
        local nodesTable = {}
        for i, n in ipairs(nodesXml) do
            local toptimeName = xmlNodeGetAttribute(n, "name")
            local toptimeVehicle = xmlNodeGetAttribute(n, "vehicle")
            local toptimeTime = xmlNodeGetAttribute(n, "time")
            table.insert(nodesTable, {toptimeName, toptimeVehicle, toptimeTime})
        end
        local personalBest = {vehicleName, topTime}
        namespace.triggerC(source, "drag-system.onClientShowTopTimeBoard", source, sortTopTimes(nodesTable), personalBest)
        nodesTable = nil
        xmlSaveFile(dataFile)
        xmlUnloadFile(dataFile)
        dataFile = nil
    end
end
namespace.addE("drag-system.onUpdateTopTimeDatabase", true)
namespace.addEH("drag-system.onUpdateTopTimeDatabase", namespace.g_root, updateTopTimeDatabase)
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...