xmlLoadString | Multi Theft Auto: Wiki Skip to content

xmlLoadString

Client-side
Server-side
Shared

This function creates an xmlnode from a string input.

OOP Syntax Help! I don't understand this!

  • Method:XML.loadstring(...)

Syntax

xmlnode|false xmlLoadString ( ​string xmlString )
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).

  • xmlnode|false: xmlnode

Code Examples

shared

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