Difference between revisions of "XmlLoadString"

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 2: Line 2:
{{Server client function}}
{{Server client function}}
This function creates an [[Xmlnode]] from a string input.
This function creates an [[Xmlnode]] from a string input.
{{New feature/item|3.0160|1.5.7||}}
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">

Revision as of 17:45, 2 September 2019

This function creates an Xmlnode from a string input.

BETA: FROM VERSION 1.5.7 ONWARDS

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> <turtle name='luxy'></turtle></animals>")

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

See Also