XmlLoadString: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Are we really doing this now?)
 
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='dutchman'></monkey> <fox name='luxy'></fox></animals>")
local rootNode = xmlLoadString("<animals test='x'><wolf name='timmy'></wolf> <fox name='luxy'></fox></animals>")


if rootNode then
if rootNode then
Line 33: Line 33:
==See Also==
==See Also==
{{Shared xml functions}}
{{Shared xml functions}}
[[ru:xmlLoadString]]
[[ru:xmlLoadString]]

Latest revision as of 14:02, 2 December 2024

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'><wolf name='timmy'></wolf> <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

See Also