Difference between revisions of "XmlLoadFile"

From Multi Theft Auto: Wiki
(Syntax)
m
 
(11 intermediate revisions by 8 users not shown)
Line 3: Line 3:
 
This function provides an alternative way to load XML files to [[getResourceConfig]].
 
This function provides an alternative way to load XML files to [[getResourceConfig]].
 
This function loads an XML file and returns the node by specifying a specific file path, while [[getResourceConfig]] allows for loading an XML file from a resource.
 
This function loads an XML file and returns the node by specifying a specific file path, while [[getResourceConfig]] allows for loading an XML file from a resource.
 
+
{{Note|To prevent memory leaks, ensure each call to [[xmlLoadFile]] has a matching call to [[xmlUnloadFile]]}}
 
==Syntax==
 
==Syntax==
<section name="Server" class="server" show="true">
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
xmlnode xmlLoadFile ( string filePath )
+
xmlnode xmlLoadFile ( string filePath [, bool readOnly = false ])
 
</syntaxhighlight>  
 
</syntaxhighlight>  
 
+
{{OOP|This function is a static function underneath the XML class.|[[XML]].load||}}
 
===Required Arguments===  
 
===Required Arguments===  
 
*'''filePath:''' The [[filepath]] of the file in the following format: '''":resourceName/path"'''. 'resourceName' is the name of the resource the file is in, and 'path' is the path from the root directory of the resource to the file.
 
*'''filePath:''' The [[filepath]] of the file in the following format: '''":resourceName/path"'''. 'resourceName' is the name of the resource the file is in, and 'path' is the path from the root directory of the resource to the file.
Line 15: Line 14:
 
:If the file is in the current resource, only the file path is necessary, e.g. ''xmlLoadFile("settings.xml")''.
 
:If the file is in the current resource, only the file path is necessary, e.g. ''xmlLoadFile("settings.xml")''.
  
</section>
+
===Optional Arguments===
 
+
*'''readOnly:''' By default, the XML file is opened with reading and writing access. You can specify ''true'' for this parameter if you only need reading access.
<section name="Client" class="client" show="true">
 
<syntaxhighlight lang="lua">
 
xmlnode xmlLoadFile ( string filePath [, string accessType = "public" ] )
 
</syntaxhighlight>
 
 
 
===Required Arguments===  
 
*'''filePath:''' The [[filepath]] of the file in the following format: '''":resourceName/path"'''. 'resourceName' is the name of the resource the file is in, and 'path' is the path from the root directory of the resource to the file.
 
:For example, if there is a file named 'settings.xml' in the resource 'ctf', it can be accessed from another resource this way: ''xmlLoadFile(":ctf/settings.xml")''.
 
:If the file is in the current resource, only the file path is necessary, e.g. ''xmlLoadFile("settings.xml")''.
 
 
{{New feature|3.0110|1.1|
 
===Optional Arguments===
 
*'''accessType :''' This setting determines whether to load the public or private version of the file at '''filePath'''
 
** "public" will load the file that is shared by all servers.
 
** "private" will load the file that only the current server is allowed to access. Note: It is only possible to load a private file if it was previously saved as ''"private"'' by the current server.
 
}}
 
</section>
 
  
 
===Returns===
 
===Returns===
 
Returns the root [[xmlnode]] object of an xml file if successful, or ''false'' otherwise.
 
Returns the root [[xmlnode]] object of an xml file if successful, or ''false'' otherwise.
 +
{{New items|3.0152|1.5|
 +
Print error if something wrong with xml.
 +
|7485}}
  
 
==Example==  
 
==Example==  
Line 46: Line 31:
 
==See Also==
 
==See Also==
 
{{XML_functions}}
 
{{XML_functions}}
 +
[[ru:xmlLoadFile]]

Latest revision as of 22:04, 18 November 2018

This function provides an alternative way to load XML files to getResourceConfig. This function loads an XML file and returns the node by specifying a specific file path, while getResourceConfig allows for loading an XML file from a resource.

[[{{{image}}}|link=]] Note: To prevent memory leaks, ensure each call to xmlLoadFile has a matching call to xmlUnloadFile

Syntax

xmlnode xmlLoadFile ( string filePath [, bool readOnly = false ])

OOP Syntax Help! I don't understand this!

Note: This function is a static function underneath the XML class.
Method: XML.load(...)

Required Arguments

  • filePath: The filepath of the file in the following format: ":resourceName/path". 'resourceName' is the name of the resource the file is in, and 'path' is the path from the root directory of the resource to the file.
For example, if there is a file named 'settings.xml' in the resource 'ctf', it can be accessed from another resource this way: xmlLoadFile(":ctf/settings.xml").
If the file is in the current resource, only the file path is necessary, e.g. xmlLoadFile("settings.xml").

Optional Arguments

  • readOnly: By default, the XML file is opened with reading and writing access. You can specify true for this parameter if you only need reading access.

Returns

Returns the root xmlnode object of an xml file if successful, or false otherwise. Print error if something wrong with xml.

Example

This example loads an XML file called settings.xml that is in a resource called ctv.

node = xmlLoadFile ( ":ctv/settings.xml" )

See Also

BETA: FROM VERSION 1.5.7 r19626 ONWARDS