<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/RU/XmlNodeSetValue?action=history&amp;feed=atom</id>
	<title>RU/XmlNodeSetValue - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/RU/XmlNodeSetValue?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/XmlNodeSetValue&amp;action=history"/>
	<updated>2026-04-30T19:08:46Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=RU/XmlNodeSetValue&amp;diff=43478&amp;oldid=prev</id>
		<title>Fabervox: Предварительный перевод(без примеров,линковок)</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=RU/XmlNodeSetValue&amp;diff=43478&amp;oldid=prev"/>
		<updated>2014-12-25T11:36:32Z</updated>

		<summary type="html">&lt;p&gt;Предварительный перевод(без примеров,линковок)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{RU/Server client function}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
Эта функция дает возможность присваивать значения к тегам в XML файлах.&lt;br /&gt;
&lt;br /&gt;
==Синтаксис== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool xmlNodeSetValue ( xmlnode theXMLNode, string value [, bool setCDATA = false] )            &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Обязательные параметры=== &lt;br /&gt;
*'''theXMLNode:''' XML узел в котором вы устанавливаете значение.&lt;br /&gt;
*'''value:''' Строка-значение присваемая узлу.&lt;br /&gt;
{{New feature/item|4.0140|1.4.0|6782|&lt;br /&gt;
*'''setCDATA:''' A boolean indicating if you want the value to be enclosed inside CDATA tags.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
===Возвращает===&lt;br /&gt;
Возвращает ''true'' если значение установлено успешно,''false'' в противном случае.&lt;br /&gt;
&lt;br /&gt;
==Примеры== &lt;br /&gt;
&amp;lt;section name=&amp;quot;Server Example&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;
In this example a sample value is inserted into a XML file.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local xmlFile = xmlLoadFile ( &amp;quot;exampleFile.xml&amp;quot; ) -- Open a file already created&lt;br /&gt;
if xmlFile then -- If it's indeed opened&lt;br /&gt;
    local node = xmlCreateChild ( xmlFile, &amp;quot;somesubnode&amp;quot; ) -- Create a new subnode&lt;br /&gt;
    local success = xmlNodeSetValue ( node, &amp;quot;somevalue&amp;quot; ) -- Set the value of it&lt;br /&gt;
    if success then -- Check if it was successful&lt;br /&gt;
        xmlSaveFile ( xmlFile ) -- Save the file&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
After both changing the value and saving the XML file with [[xmlSaveFile]], the file will look like this:&lt;br /&gt;
&amp;lt;section name=&amp;quot;exampleFile.xml&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;somenode&amp;gt;&lt;br /&gt;
	&amp;lt;somesubnode&amp;gt;somevalue&amp;lt;/somesubnode&amp;gt;&lt;br /&gt;
&amp;lt;/somenode&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client Example: Save and load from a clientside XML&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This shows an example of a clientside XML file. You can use this to store user preferences and load them the next time the script loads. Almost always, you should have an options GUI for clients to interact with to set these values.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
Since the XML will change, it should NOT be included in the resource's meta.xml file. MTA will think that file is corrupted and will download it again from the server. Instead, you should create the XML within the script, and then load it within the script on future script runs if it exists.&lt;br /&gt;
&lt;br /&gt;
'''This xml will be created from the script following it below'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;root&amp;gt;&lt;br /&gt;
    &amp;lt;hud_display&amp;gt;&lt;br /&gt;
        &amp;lt;IconSizeX&amp;gt;60&amp;lt;/IconSizeX&amp;gt;&lt;br /&gt;
        &amp;lt;IconSizeY&amp;gt;60&amp;lt;/IconSizeY&amp;gt;&lt;br /&gt;
    &amp;lt;/hud_display&amp;gt;&lt;br /&gt;
    &amp;lt;hud_binds&amp;gt;&lt;br /&gt;
        &amp;lt;weaponSlot0&amp;gt;tab&amp;lt;/weaponSlot0&amp;gt;&lt;br /&gt;
        &amp;lt;weaponSlot1&amp;gt;1&amp;lt;/weaponSlot1&amp;gt;&lt;br /&gt;
    &amp;lt;/hud_binds&amp;gt;&lt;br /&gt;
&amp;lt;/root&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''This script will create the xml or load it if it exists'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function ClientResourceStart ()&lt;br /&gt;
	xmlRootTree = xmlLoadFile ( &amp;quot;userSettings.xml&amp;quot; ) --Attempt to load the xml file	&lt;br /&gt;
&lt;br /&gt;
	if xmlRootTree then -- If the xml loaded then...&lt;br /&gt;
		xmlHudBranch = xmlFindChild(xmlRootTree,&amp;quot;hud_display&amp;quot;,0) -- Find the hud sub-node&lt;br /&gt;
		xmlBindsBranch = xmlFindChild(xmlRootTree,&amp;quot;hud_binds&amp;quot;,0) -- Find the binds sub-node&lt;br /&gt;
		outputChatBox ( &amp;quot;XML Found and Loaded&amp;quot; )&lt;br /&gt;
	else -- If the xml does not exist then...&lt;br /&gt;
		xmlRootTree = xmlCreateFile ( &amp;quot;userSettings.xml&amp;quot;, &amp;quot;root&amp;quot; ) -- Create the xml file	&lt;br /&gt;
		xmlHudBranch = xmlCreateChild ( xmlRootTree, &amp;quot;hud_display&amp;quot; ) -- Create the hud sub-node under the root node&lt;br /&gt;
		xmlBindsBranch = xmlCreateChild ( xmlRootTree, &amp;quot;hud_binds&amp;quot; )-- Create the binds sub-node under the root node&lt;br /&gt;
		xmlNodeSetValue (xmlCreateChild ( xmlHudBranch, &amp;quot;IconSizeX&amp;quot;), &amp;quot;60&amp;quot; ) --Create sub-node values under the hud sub-node&lt;br /&gt;
		xmlNodeSetValue (xmlCreateChild ( xmlHudBranch, &amp;quot;IconSizeY&amp;quot;), &amp;quot;60&amp;quot; ) --Create sub-node values under the hud sub-node&lt;br /&gt;
		xmlNodeSetValue (xmlCreateChild ( xmlBindsBranch, &amp;quot;weaponSlot0&amp;quot;), &amp;quot;tab&amp;quot; ) --Create sub-node values under the binds sub-node&lt;br /&gt;
		xmlNodeSetValue (xmlCreateChild ( xmlBindsBranch, &amp;quot;weaponSlot1&amp;quot;), &amp;quot;1&amp;quot; ) --Create sub-node values under the binds sub-node&lt;br /&gt;
		outputChatBox ( &amp;quot;XML Created&amp;quot; )&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	--Retrieve a single sub-node name or value&lt;br /&gt;
	outputChatBox( &amp;quot;Node name: &amp;quot;..xmlNodeGetName (xmlFindChild(xmlHudBranch,&amp;quot;IconSizeX&amp;quot;,0)), 0, 0, 255 ) --blue outputs&lt;br /&gt;
	outputChatBox( &amp;quot;Node Value: &amp;quot;..xmlNodeGetValue (xmlFindChild(xmlHudBranch,&amp;quot;IconSizeX&amp;quot;,0)), 0, 0, 255 ) --blue outputs&lt;br /&gt;
	&lt;br /&gt;
        --Retrieve multiple sub-node names or values	&lt;br /&gt;
	xmlHudChildrenTable = xmlNodeGetChildren ( xmlHudBranch ) --Create a table of this branch's children&lt;br /&gt;
	for i,node in pairs(xmlHudChildrenTable ) do --Loop through the branch's children for sub-nodes&lt;br /&gt;
            outputChatBox( &amp;quot;Node name: &amp;quot;..xmlNodeGetName (node), 0, 255, 0 ) --green outputs&lt;br /&gt;
	    outputChatBox( &amp;quot;Node Value: &amp;quot;..xmlNodeGetValue(node), 0, 255, 0 ) --green outputs&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addEventHandler ( &amp;quot;onClientResourceStart&amp;quot;, resourceRoot, ClientResourceStart )&lt;br /&gt;
 &lt;br /&gt;
function ClientResourceStop ()&lt;br /&gt;
	xmlSaveFile ( xmlRootTree ) --Save the xml from memory for use next time&lt;br /&gt;
	xmlUnloadFile ( xmlRootTree ) --Unload the xml from memory&lt;br /&gt;
	outputChatBox ( &amp;quot;Saved and unloaded the XML.&amp;quot; )&lt;br /&gt;
end&lt;br /&gt;
addEventHandler ( &amp;quot;onClientResourceStop&amp;quot;, resourceRoot, ClientResourceStop )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Смотрите также==&lt;br /&gt;
{{RU/XML functions}}&lt;/div&gt;</summary>
		<author><name>Fabervox</name></author>
	</entry>
</feed>