Search the Community
Showing results for tags 'xml'.
-
سلام عليكم ورحمة الله وبركاته شباب سؤال فقط كيف اسوي جريد لست فيها رو الرو هذا جبته من xml زي الفري روم مثلا
-
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!
-
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.
-
Hey , this is my code , He don't create the XML file and i tried this : ( Only Client ) function createXML() if source == vehPanel.button[1] then settings = xmlCreateFile("savedsettings.xml","settings") if guiCheckBoxGetSelected(vehPanel.checkbox[1]) then xmlNodeSetAttribute(settings, "car", "true") else xmlNodeSetAttribute(settings, "car", "false") end end addEventHandler("onClientGUIClick", getRootElement(), createXML) And this : function createXML() settings = xmlCreateFile("savedsettings.xml","settings") if guiCheckBoxGetSelected(vehPanel.checkbox[1]) then xmlNodeSetAttribute(settings, "car", "true") else xmlNodeSetAttribute(settings, "car", "false") end end addEventHandler("onClientResourceStart", getRootElement(), createXML) And this : function createXML() local exists = fileExists ( "savedsettings.xml" ) if not exists then settings = xmlCreateFile("savedsettings.xml","settings") if guiCheckBoxGetSelected(vehPanel.checkbox[1]) then xmlNodeSetAttribute(settings, "car", "true") else xmlNodeSetAttribute(settings, "car", "false") end end addEventHandler("onClientResourceStart", getRootElement(), createXML) And no one create xml , i need some help please , this is the end code : function load() local currentFile = xmlLoadFile ("savedsettings.xml") if xmlNodeGetAttribute(currentFile, "car") == "true" then guiCheckBoxSetSelected(vehPanel.checkbox[1], true) veh1() end end load()