XML library |
Makinit « Citoyen » 1396749420000
| 1 | ||
Code Lua 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 local namePattern = "[%a_:][%w%.%-_:]*" This is a set of functions I made to do the map editing in #sketch. It's a parser that can handle most XML documents and a generator that takes the output format (DOM) of the parser. The parseXml and generateXml functions both have a fast parameter. The fast mode does not escape and unescape text and cannot handle exotic nodes. However, using this is highly recommended if you only use it for simple XML like the map XML, as it's considerably faster. If you do this, you can remove the (un)escape functions, as they would only take space. This is the format of the Document Object Model: Code Lua 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 --<C><P /><Z><S><S L="200" Y="300" P="0,0,0.3,0.2,0,0,0,0" T="0" X="400" H="50" /></S><D><T X="350" Y="275" /><F X="450" Y="270" /></D><O /></Z></C> You can use the path method to navigate through the DOM more easily. It takes any element as first parameter and then the path of element names you want to take. Feel free to use, modify and distribute this code. Please leave your comments, questions, suggestions and issues as a reply to this thread. Code Lua 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 --example which gives grounds random colours and mixes up decorations Dernière modification le 1481367960000 |
Uditya « Citoyen » 1396763220000
| 0 | ||
Wow thats amzaing ! |
Benbirkralm « Citoyen » 1396775520000
| 0 | ||
I like it. It's so crazy! |
0 | ||
haha this is really nice! does this only change the tribe house map? |
Makinit « Citoyen » 1396790400000
| 0 | ||
Arber a dit : It should change any user map that's loaded in the tribe house. |
0 | ||
Makinit a dit : Oh.. because when i change map to /np 0 it automatically changes to tribe house map |
Shamousey « Consul » 1396803180000
| 0 | ||
Arber a dit : Older vanilla maps don't have an XML. |
Mouldychesse « Citoyen » 1396808700000
| 0 | ||
I typed in one of the scripts with my maps. |
Makinit « Citoyen » 1396898940000
| 0 | ||
The parent property in the node table is removed, because it was not necessary and makes creating deep copies of nodes difficult. The parents are now kept track of inside the parseXml function. In the generateXml function, the fast parameter was previously not passed to recursive calls, this is now fixed. |
Epicsouris « Citoyen » 1396900980000
| 0 | ||
Love the amp& lt& commands, makes it noob friendly :3 |
Makinit « Citoyen » 1397162220000
| 0 | ||
Epicsouris a dit : You can also use these to properly display text containing XML control characters, if that's what you're referring to. |
Baasbase « Citoyen » 1398858720000
| 0 | ||
thx mak |
Ninjasmaus « Citoyen » 1434271320000
| 0 | ||
Hi there Mak, I was wondering how you could extract information from the XML code. For example I'm trying to find everything within <p></p> and from your generator it would be in [1] right? However when I print(dom[1]) it doesn't give me anything. |
Makinit « Citoyen » 1434283380000
| 0 | ||
Ninjasmaus a dit : Yes, if P is always the first element. To be sure you could use path: a dit : Ninjasmaus a dit : The DOM elements are just tables, so if you want to display them, you would need a way to convert them to text. For example by converting back to XML: a dit : |