How to resolve the algorithm XML/Output step by step in the Lua programming language
How to resolve the algorithm XML/Output step by step in the Lua programming language
Table of Contents
Problem Statement
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of
Let's start with the solution:
Step by Step solution about How to resolve the algorithm XML/Output step by step in the Lua programming language
Source code in the lua programming language
require("LuaXML")
function addNode(parent, nodeName, key, value, content)
local node = xml.new(nodeName)
table.insert(node, content)
parent:append(node)[key] = value
end
root = xml.new("CharacterRemarks")
addNode(root, "Character", "name", "April", "Bubbly: I'm > Tam and <= Emily")
addNode(root, "Character", "name", "Tam O'Shanter", 'Burns: "When chapman billies leave the street ..."')
addNode(root, "Character", "name", "Emily", "Short & shrift")
print(root)
<CharacterRemarks>
<Character name="April">Bubbly: I'm > Tam and <= Emily</Character>
<Character name="Tam O'Shanter">Burns: "When chapman billies leave the street ..."</Character>
<Character name="Emily">Short & shrift</Character>
</CharacterRemarks>
xmlStr = xml.str(root):gsub("'", "'"):gsub(""", '"')
print(xmlStr)
<CharacterRemarks>
<Character name="April">Bubbly: I'm > Tam and <= Emily</Character>
<Character name="Tam O'Shanter">Burns: "When chapman billies leave the street ..."</Character>
<Character name="Emily">Short & shrift</Character>
</CharacterRemarks>
You may also check:How to resolve the algorithm Arithmetic/Rational step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Web scraping step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm The sieve of Sundaram step by step in the Haskell programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the C++ programming language
You may also check:How to resolve the algorithm Flatten a list step by step in the GNU APL programming language