Difference between revisions of "XmlLoadString"

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server client function}}
{{Server client function}}
{{New feature/item|3.0160|1.6||This function creates an [[Xmlnode]] from a string input.}}
{{New feature/item|3.0158|1.5.7|19626|This function creates an [[Xmlnode]] from a string input.}}
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 16: Line 16:
This example loads an XML string and loops the children while outputting to debugscript.
This example loads an XML string and loops the children while outputting to debugscript.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local rootNode = xmlLoadString("<animals test='x'><monkey name='crosroad'></monkey> <turtle name='luxy'></turtle></animals>")
local rootNode = xmlLoadString("<animals test='x'><monkey name='crosroad'></monkey> <fox name='luxy'></fox></animals>")


if rootNode then
if rootNode then
local rootAttributes = xmlNodeGetAttributes(rootNode)
local rootAttributes = xmlNodeGetAttributes(rootNode)
outputDebugString("Root Node", "Name: "..xmlNodeGetName(rootNode),  "Attributes :"..toJSON(rootAttributes))
print("Root Node", "Name: "..xmlNodeGetName(rootNode),  "Attributes :"..toJSON(rootAttributes))
local children = xmlNodeGetChildren(rootNode)
local children = xmlNodeGetChildren(rootNode)
Line 26: Line 26:
for i, childNode in ipairs(children) do
for i, childNode in ipairs(children) do
local attributes = xmlNodeGetAttributes(childNode)
local attributes = xmlNodeGetAttributes(childNode)
outputDebugString("Child #"..i, "Name: "..xmlNodeGetName(childNode), "Attributes :"..toJSON(attributes))
print("Child #"..i, "Name: "..xmlNodeGetName(childNode), "Attributes :"..toJSON(attributes))
end
end
end
end
</syntaxhighlight>
</syntaxhighlight>
==Requirements==
{{Requirements|1.5.7-9.19626|1.5.7-9.19626|}}


==See Also==
==See Also==
{{Shared xml functions}}
{{Shared xml functions}}
[[ru:xmlLoadString]]
[[ru:xmlLoadString]]

Latest revision as of 13:58, 25 October 2020

This function creates an Xmlnode from a string input.

Syntax

xmlnode xmlLoadString ( string xmlString )

OOP Syntax Help! I don't understand this!

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

Required Arguments

  • xmlString: A string containing XML data

Returns

Returns the root xmlnode object of an xml string if successful, or false otherwise (invalid XML string).

Example

This example loads an XML string and loops the children while outputting to debugscript.

local rootNode = xmlLoadString("<animals test='x'><monkey name='crosroad'></monkey> <fox name='luxy'></fox></animals>")

if rootNode then
	local rootAttributes = xmlNodeGetAttributes(rootNode)
	print("Root Node", "Name: "..xmlNodeGetName(rootNode),  "Attributes :"..toJSON(rootAttributes))
	
	local children = xmlNodeGetChildren(rootNode)
	
	for i, childNode in ipairs(children) do
		local attributes = xmlNodeGetAttributes(childNode)
		print("Child #"..i, "Name: "..xmlNodeGetName(childNode), "Attributes :"..toJSON(attributes))
	end
end

Requirements

Minimum supported server 1.5.7-9.19626
Minimum supported client 1.5.7-9.19626

Note: Using this function/event requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version server="1.5.7-9.19626" client="1.5.7-9.19626" />

See Also

BETA: FROM VERSION 1.5.7 r19626 ONWARDS