Difference between revisions of "XmlLoadFile"

From Multi Theft Auto: Wiki
m
Line 4: Line 4:
 
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.
  
==Syntax==  
+
==Syntax==
<section name="Server" class="server" show="true">
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
xmlnode xmlLoadFile ( string filename, [ resource fromResource = getThisResource () ] )
+
xmlnode xmlLoadFile ( string filePath )
 
</syntaxhighlight>  
 
</syntaxhighlight>  
  
 
===Required Arguments===  
 
===Required Arguments===  
*'''filename:''' the path to the file you wish to load.  This is a path relative to the current or specified resource root directory.
+
*'''filePath:''' the path 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: ''getResourceConfig(":ctf/settings.xml")''.
===Optional Arguments===
+
:If the file is in the current resource, only the file path is necessary, e.g. ''getResourceConfig("settings.xml")''.
{{OptionalArg}}
 
*'''fromResource:''' the [[resource]] whose directory will be used as the root for the filename specified.
 
</section>
 
 
 
<section name="Client" class="client" show="true">
 
<syntaxhighlight lang="lua">
 
xmlnode xmlLoadFile ( string filename )             
 
</syntaxhighlight>
 
 
 
===Required Arguments===
 
*'''filename:''' The [[filepath]] to the file you wish to load. '''.
 
</section>
 
  
 
===Returns===
 
===Returns===
Line 31: Line 18:
  
 
==Example==  
 
==Example==  
This example loads an XML file called ''test.xml''.
+
This example loads an XML file called ''settings.xml'' that is in a resource called ''ctv''.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
node = xmlLoadFile ( "test.xml" )
+
node = xmlLoadFile ( ":ctv/settings.xml" )
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
==See Also==
 
==See Also==
 
{{XML_functions}}
 
{{XML_functions}}

Revision as of 03:16, 30 July 2009

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.

Syntax

xmlnode xmlLoadFile ( string filePath )

Required Arguments

  • filePath: the path 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: getResourceConfig(":ctf/settings.xml").
If the file is in the current resource, only the file path is necessary, e.g. getResourceConfig("settings.xml").

Returns

Returns the root xmlnode object of an xml file if successful, or false otherwise.

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