Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
Latest commit
54 lines (44 loc) · 1.85 KB
/
Copy pathinit.lua
File metadata and controls
54 lines (44 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
--- A simple XML (de)serializer
localmousexml= {}
localXmlNode=require("XmlNode")
localXmlDoc=require("XmlDoc")
--- Parses an XML string
--- @paramxmlstring
--- @returnXmlDoc?
functionmousexml.parse(xml)
localdocument=XmlDoc:new()
localcurr_node=document
-- Parse nodes. will fail if attributes contain >, use a more robust parser to handle
--- @typestring
forclosing, name, attrib, leaf, textinxml:gmatch("<(/?)([%w_]+)(.-)(/?)>%s*([^<]*)%s*") do
ifclosing=="/" then
ifcurr_node==nilorcurr_node==documentthenreturnnilend
ifleaf=="/" thenreturnnilend-- </Name/> doesn't make sense
ifname~=curr_node.namethenreturnnilend-- <a></b> doesn't make sense
ifattrib~="" thenreturnnilend-- </Name a="b"> doesn't make sense
curr_node=curr_node.parent-- go up one level
else
-- Make a new node
localnode=XmlNode:new(name)
-- Parse attributes
fork, vinattrib:gmatch([[%s([%a_:][^%s%c]-)%s*=%s*"(.-)"]]) do-- attribute key/value matching. will fail if attribute value contain " (through escaping), use a more robust parser to handle
node.attributes[k] =v
end
curr_node:addChild(node)
ifleaf=="" then
-- Not a self-closing tag
curr_node=node
end
end
iftext~="" then
-- Link the text to the current node. If a text is already linked, append this one with a space.
localcurr_text=curr_node.text
curr_node.text= (curr_textandcurr_text.."" or"") ..text
end
end
ifcurr_node~=documentthenreturnnilend
returndocument
end
mousexml.XmlNode=XmlNode
mousexml.XmlDoc=XmlDoc
returnmousexml