XmlLoadString: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
Line 20: | Line 20: | ||
if rootNode then | if rootNode then | ||
local rootAttributes = xmlNodeGetAttributes(rootNode) | local rootAttributes = xmlNodeGetAttributes(rootNode) | ||
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) | ||
print("Child #"..i, "Name: "..xmlNodeGetName(childNode), "Attributes :"..toJSON(attributes)) | |||
end | end | ||
end | end |
Revision as of 18:22, 2 September 2019
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> <turtle name='luxy'></turtle></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