Changeset 163 for trunk/lingosource/castlib2/PseudoXMLPS.ls
- Timestamp:
- 04/06/08 11:11:43 (4 years ago)
- File:
-
- 1 edited
-
trunk/lingosource/castlib2/PseudoXMLPS.ls (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lingosource/castlib2/PseudoXMLPS.ls
r150 r163 1 -- PseudoXMLPS 2 ----------------------------------- 3 -- CREATED: 4 -- 06.03.2008 5 -- 6 -- DESCRIPTION: 1 7 -- Pseudo XML by Alex da Franca ©2003 2 8 -- Convert a lingo list to a XML like string and back 3 9 4 -- alex am Freitag 21.April.2006 16:31:57 5 -------------------------------------------------------- 6 -- fixed a bug in "mBuildXMLString" many thanks to Olaf Schliesing for pointing this out 7 8 -- alex am 28.11.06 um 16:41:00 9 -------------------------------------------------------- 10 -- finally added a tag property, when writing xml, so the ilk of the object gets stored 11 -- so, when reading back the xml file, we do not convert a node by accident to a value 12 -- when a string evaluates to a value "by accident" 13 14 --------------------------------- 15 -- Scriptmarker: changes alex (04.04.2007 at 10:22 Uhr) // Scriptmarker 16 -- added escaping of: 17 -- & -> & 18 -- ' -> ' 19 -- " -> " 20 -- and vice versa. Until now I only escaped < and >, but ampersand, apostrophe and quote must also be escaped for proper xml 21 22 -- I als added "support" for the CData tag, which allows you to escape the whole contents of a node. 23 -- support is only done through ignoring esaping the special characters, wehn BUILDING the xml string. 24 -- So the user can decide on his own, which nodes s/he wants to be masked inside a CData section 25 -- (otherwise I'd have to mask EVERY string and try to unmask EVERY node. Now the user is on his own) 26 27 -- Example: 10 -- 11 -- REQUIRES: 12 -- (Prerequisites) 13 -- 14 -- USAGE: 28 15 -- myList = [#stringWithInvalidChars:"A string with invalid chars like <> and & and ' and " & QUOTE] 29 16 -- myList[#stringWithInvalidChars] = "<![CDATA[" & myList[#stringWithInvalidChars] & "]]>" … … 41 28 -- end if 42 29 -- end repeat 30 -- 31 -- HISTORY: 32 33 -- alex am Freitag 21.April.2006 16:31:57 34 -- fixed a bug in "mBuildXMLString" many thanks to Olaf Schliesing for pointing this out 35 -- 36 -- alex am 28.11.06 um 16:41:00 37 -- finally added a tag property, when writing xml, so the ilk of the object gets stored 38 -- so, when reading back the xml file, we do not convert a node by accident to a value 39 -- when a string evaluates to a value "by accident" 40 -- 41 -- Scriptmarker: changes alex (04.04.2007 at 10:22 Uhr) // Scriptmarker 42 -- added escaping of: 43 -- & -> & 44 -- ' -> ' 45 -- " -> " 46 -- and vice versa. Until now I only escaped < and >, but ampersand, apostrophe and quote must also be escaped for proper xml 47 -- I als added "support" for the CData tag, which allows you to escape the whole contents of a node. 48 -- support is only done through ignoring esaping the special characters, wehn BUILDING the xml string. 49 -- So the user can decide on his own, which nodes s/he wants to be masked inside a CData section 50 -- (otherwise I'd have to mask EVERY string and try to unmask EVERY node. Now the user is on his own) 51 -- TODO: 52 -- - 53 ----------------------------------- 54 55 56 57 58 59 43 60 44 61 … … 112 129 -- xxxxxxxxxxxxxxxxxx Convert lingo list (also nested lists) to XML stylish string 113 130 114 -- Parameters: 131 on mGetXMLStringFromList me, listref, docName, strict, dontReplaceGT, withParams 132 ----------------------------------- 133 -- CREATED: 06.03.2008 134 -- ACTION: Convert lingo list (also nested lists) to XML stylish string 135 -- INPUT: 115 136 -- <listref> format: property list or linear list 116 137 -- <docName> format: #string; optional. if omitted "Untitled" is used for the XML document name 117 -- strict=> boolean; avoid spaces in tag names118 -- dontReplaceGT=> boolean; dont replace < and >119 -- withParams=> boolean; write attribute in tag for the lingo ilk => bigger xml files and unfortunately it is slower to parse138 -- <strict> => boolean; avoid spaces in tag names 139 -- <dontReplaceGT> => boolean; dont replace < and > 140 -- <withParams> => boolean; write attribute in tag for the lingo ilk => bigger xml files and unfortunately it is slower to parse 120 141 ----------------------------- (I thought avoiding value() would help, but in this case the additional text parsing of the attributes tag slows down) 121 122 -- Example: 123 -- saveString = mGetXMLStringFromList(me, lingo_list, "documentName") 124 125 on mGetXMLStringFromList me, listref, docName, strict, dontReplaceGT, withParams 142 -- RETURNS: string 143 -- EXAMPLE: saveString = mGetXMLStringFromList(me, lingo_list, "documentName") 144 ----------------------------------- 145 126 146 -- ms = the milliseconds 127 147 if voidP(strict) then strict = 0 … … 152 172 -- xxxxxxxxxxxxxxxxxx Convert XML stylish string to lingo list 153 173 154 -- Parameters: 174 175 on mGetListFromXMLString me, str, convertValues, withParams 176 ----------------------------------- 177 -- CREATED: 06.03.2008 178 -- ACTION: Description 179 -- INPUT: 155 180 -- <str> format: #string; split a string using <> and </> tags into lingo list 156 181 -- <convertValues> #integer 0=>don't convert (fast, all values are strings), 1 => convert only numbers (slower); 2 => try to convert all data, even colors (slow) 157 158 -- Example: 159 --lingo_list = mGetListFromXMLString(me, saveString)160 161 on mGetListFromXMLString me, str, convertValues, withParams 182 -- <withParams> : #boolean : parse parameters too. new, not very well tested 183 -- RETURNS: property list 184 -- EXAMPLE: lingo_list = mGetListFromXMLString(me, saveString) 185 -- CHANGES: implemented parameter parsing 186 ----------------------------------- 162 187 163 188 ms = the milliseconds … … 193 218 194 219 -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 195 -- MUCH FASTER than the above: Use the XML xtra to parse the string 196 -- BUT it must be a valid xml string, the above is slower but allows more malformed xml 197 198 -- Parameters: 220 221 222 property pXmlxtraversion 223 224 on mGetListFromXMLStringX me, str, convertValues, withParams 225 ----------------------------------- 226 -- CREATED: 06.03.2008 227 -- ACTION: Convert xml string to lingo list using the xmlparser xtra, if possible 228 -- MUCH FASTER than the above: Use the XML xtra to parse the string 229 -- BUT it must be a valid xml string, the above is slower but allows more malformed xml 230 -- INPUT: 199 231 -- <str> format: #string; split a string using <> and </> tags into lingo list 200 232 -- <convertValues> #integer … … 202 234 -- -- -- 1 => convert only integer() and float() (slower) 203 235 -- -- -- 2 => try to convert all data with value(), even parse for colors in hexstring format (slow) 204 205 -- Example: 206 -- lingo_list = mGetListFromXMLStringX(me, saveString) 207 208 property pXmlxtraversion 209 210 on mGetListFromXMLStringX me, str, convertValues, withParams 236 -- RETURNS: property list 237 -- EXAMPLE: lingo_list = mGetListFromXMLStringX(me, saveString) 238 -- CHANGES: resorts to the slower lingo function on xml parser error. So this handler can always be used. 239 ----------------------------------- 211 240 212 241 if ilk(str) <> #string then str = string(str) … … 289 318 290 319 end 320 321 -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 322 on _______________READ_WRITE_EXTERNAL_FILES 323 end 324 -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 325 326 on mReadXML_2_List me, thePath 327 ----------------------------------- 328 -- CREATED: 06.03.2008 329 -- ACTION: read external xml file to lingo list 330 -- INPUT: <thePath> : string ; optional pathname. if no pathname or "", then a file save dialog is shown 331 -- RETURNS: property list 332 ----------------------------------- 333 334 dertext = xscr(#FileIOFunktionen).mGetTextFromFile(thePath) 335 if length(dertext) > 0 then return xscr(#PseudoXMLPS).mGetListFromXMLStringX(dertext) 336 return [:] 337 end 338 339 -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 340 341 on mSaveList_2_XML me, theList, thePath 342 ----------------------------------- 343 -- CREATED: 06.03.2008 344 -- ACTION: write liongo list to external xml file 345 -- INPUT: 346 -- <theList> : linear or property list 347 -- <thePath> : string ; optional pathname. if no pathname or "", then a file selection dialog is shown 348 -- RETURNS: full pathname of newly created file, if successful, otherwise 0 349 ----------------------------------- 350 351 if not(listP(theList)) then return 0 352 theResult = xscr(#PseudoXMLPS).mGetXMLStringFromList(theList) 353 return xscr(#FileIOFunktionen).mSaveToTextFile(theResult, thePath) 354 end 355 291 356 292 357 -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx … … 940 1005 941 1006 if ilk(retlist) = #proplist then 942 retlist.addProp(symbol(inputlist[n].getaprop(#name)), val)1007 retlist.addProp(symbol(inputlist[n].getaprop(#name)), val) 943 1008 else 944 1009 retlist.add(val) … … 994 1059 995 1060 else 996 call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Row "&n&" Cell "&m&" is not a property list")1061 call(#mPut, mGetXScript(), "mParseExcelXML: Row "&n&" Cell "&m&" is not a property list") 997 1062 end if -- if ilk(thisCell) = #proplist then 998 1063 … … 1000 1065 1001 1066 else 1002 call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Row "&n&" is not a list")1067 call(#mPut, mGetXScript(), "mParseExcelXML: Row "&n&" is not a list") 1003 1068 end if -- if listP(currRow) then 1004 1069 … … 1006 1071 1007 1072 else 1008 call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Table not found")1073 call(#mPut, mGetXScript(), "mParseExcelXML: Table not found") 1009 1074 end if -- if listP(xmlList) then 1010 1075 1011 1076 else 1012 call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Worksheet not found")1077 call(#mPut, mGetXScript(), "mParseExcelXML: Worksheet not found") 1013 1078 end if -- if ilk(xmlList) = #proplist then 1014 1079 1015 1080 else 1016 call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Workbook not found")1081 call(#mPut, mGetXScript(), "mParseExcelXML: Workbook not found") 1017 1082 end if -- if ilk(xmlList) = #proplist then 1018 1083 1019 1084 else 1020 call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: ROOT is not a property list")1085 call(#mPut, mGetXScript(), "mParseExcelXML: ROOT is not a property list") 1021 1086 end if --if ilk(xmlList) = #proplist then 1022 1087 1023 1088 else 1024 call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Xml parser makelist() returned empty list")1089 call(#mPut, mGetXScript(), "mParseExcelXML: Xml parser makelist() returned empty list") 1025 1090 end if -- if count(xmlList) > 0 then 1026 1091 1027 1092 else 1028 call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Xml parser makelist() failed")1093 call(#mPut, mGetXScript(), "mParseExcelXML: Xml parser makelist() failed") 1029 1094 end if -- if listP(xmlList) then 1030 1095 1031 1096 else 1032 call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Xml parser error: "&xmlp.getError())1097 call(#mPut, mGetXScript(), "mParseExcelXML: Xml parser error: "&xmlp.getError()) 1033 1098 end if -- if voidP(xmlp.getError()) then 1034 1099
Note: See TracChangeset
for help on using the changeset viewer.
