Changeset 228 for trunk/lingosource/castlib2/PseudoXMLPS.ls
- Timestamp:
- 03/20/09 18:08:22 (3 years ago)
- File:
-
- 1 edited
-
trunk/lingosource/castlib2/PseudoXMLPS.ls (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lingosource/castlib2/PseudoXMLPS.ls
r215 r228 2 2 ----------------------------------- 3 3 -- CREATED: 4 -- 06.03.20084 -- 2002 5 5 -- 6 6 -- DESCRIPTION: 7 7 -- Pseudo XML by Alex da Franca c2003 8 -- Convert a lingo list to a XML like string and back8 -- Convert a lingo list to a XML like string and back 9 9 10 10 -- 11 11 -- REQUIRES: 12 -- (Prerequisites) 12 -- only the functions mSaveList_2_XML() and mReadXML_2_List() require my system of library scripts 13 -- in order to write and read text with fileio. All other functions have no dependencies 14 -- Either get these scripts from my website, or replace the write/read stuff with your own fileIO handlers 15 -- That is: 16 -- * movie script "aleXtrasMovieScript" 17 -- * parent script "commonMovieScript" 18 -- * parent script "FileIOFunktionen" 13 19 -- 14 20 -- USAGE: 21 -- ---------- please see the comments for each handler for a how-to. 22 -- ---------- nonetheless here are some fast start comments with the minimum amount of parameters 23 -- PseudoXMLPS = new(script "PseudoXMLPS") 24 -- -- Convert a list to an xml string: 25 -- xmlString = PseudoXMLPS.mGetXMLStringFromList(["one", "two", [#prop: 3]]) 26 -- lingolist = PseudoXMLPS.mGetListFromXMLStringX(xmlString) 27 -- ---------- basically that's it 28 -- 29 -- ---------- another "hack" to be aware of is the following: 30 -- ---------- linear lists get identified by having a nodename which starts with the exact string "item" 31 -- ---------- so if an xml node like <item1>one</item1> is encountered, it is treated as linear list: ["one"] 32 -- ---------- and NOT as [#item1:"one"] 33 -- 34 -- ---------- the mGetXMLStringFromList() function escapes the reserved xml chars <> and & and ' and " by default 35 -- ---------- if for some reason you rather want to enclose the contents in a <![CDATA[ tag, use the dontReplaceGT flag. 36 --------------------------------------------- EXAMPLE for <dontReplaceGT = 1> (dontReplaceGT means don't replace "greater than" btw...): 37 -- 15 38 -- myList = [#stringWithInvalidChars:"A string with invalid chars like <> and & and ' and " & QUOTE] 16 39 -- myList[#stringWithInvalidChars] = "<![CDATA[" & myList[#stringWithInvalidChars] & "]]>" … … 28 51 -- end if 29 52 -- end repeat 53 --------------------------------------------- please note, that the above example is ONLY needed, if you use dontReplaceGT = 1 !! 30 54 -- 31 55 -- HISTORY: … … 129 153 -- ACTION: Convert lingo list (also nested lists) to XML stylish string 130 154 -- INPUT: 131 --<listref> format: property list or linear list132 --<docName> format: #string; optional. if omitted "Untitled" is used for the XML document name155 -- <listref> format: property list or linear list 156 -- <docName> format: #string; optional. if omitted "Untitled" is used for the XML document name 133 157 -- <strict> => boolean; avoid spaces in tag names 134 158 -- <dontReplaceGT> => boolean; dont replace < and > 135 159 -- <withParams> => boolean; write attribute in tag for the lingo ilk => bigger xml files and unfortunately it is slower to parse 136 ----------------------------- (I thought avoiding value() would help, but in this case the additional text parsing of the attributes tag slows down)160 ----------------------------- (I thought avoiding value() would help, but in this case the additional text parsing of the attributes tag slows down) 137 161 -- RETURNS: string 138 162 -- EXAMPLE: saveString = mGetXMLStringFromList(me, lingo_list, "documentName") … … 173 197 -- ACTION: Description 174 198 -- INPUT: 175 --<str> format: #string; split a string using <> and </> tags into lingo list176 --<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)199 -- <str> format: #string; split a string using <> and </> tags into lingo list 200 -- <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) 177 201 -- <withParams> : #boolean : parse parameters too. new, not very well tested 178 202 -- RETURNS: property list … … 224 248 -- BUT it must be a valid xml string, the above is slower but allows more malformed xml 225 249 -- INPUT: 226 --<str> format: #string; split a string using <> and </> tags into lingo list227 --<convertValues> #integer228 ---- -- 0 => don't convert (fast, all values are strings)229 ---- -- 1 => convert only integer() and float() (slower)230 ---- -- 2 => try to convert all data with value(), even parse for colors in hexstring format (slow)250 -- <str> format: #string; split a string using <> and </> tags into lingo list 251 -- <convertValues> #integer 252 -- -- -- 0 => don't convert (fast, all values are strings) 253 -- -- -- 1 => convert only integer() and float() (slower) 254 -- -- -- 2 => try to convert all data with value(), even parse for colors in hexstring format (slow) 231 255 -- RETURNS: property list 232 256 -- EXAMPLE: lingo_list = mGetListFromXMLStringX(me, saveString) … … 306 330 li = mConvertXMLPropList(me, [xx], convertValues, dontEscapeSpecialChars) 307 331 308 -- put "x" && the milliseconds - ms332 -- put "PseudoXMLPS: mGetListFromXMLStringX:" && the milliseconds - ms 309 333 310 334 if not(listP(li)) then return [:] … … 328 352 329 353 dertext = xscr(#FileIOFunktionen).mGetTextFromFile(thePath) 330 if length(dertext) > 0 then return xscr(#PseudoXMLPS).mGetListFromXMLStringX(dertext)354 if length(dertext) > 0 then return mGetListFromXMLStringX(me, dertext) 331 355 return [:] 332 356 end … … 345 369 346 370 if not(listP(theList)) then return 0 347 theResult = xscr(#PseudoXMLPS).mGetXMLStringFromList(theList)371 theResult = mGetXMLStringFromList(me, theList) 348 372 return xscr(#FileIOFunktionen).mSaveToTextFile(theResult, thePath) 349 373 end … … 757 781 758 782 if val.length = 7 then 759 if (val.char[1] = "#") and (offset(val.char[2], "abcdef0123456789") > 0) then return rgb(val) 783 if (val.char[1] = "#") then 784 isColor = 1 785 repeat with n = 2 to 7 786 if (offset(val.char[n], "abcdef0123456789") < 1) then 787 isColor = 0 788 exit repeat 789 end if 790 end repeat 791 if isColor = 1 then return rgb(val) 792 end if 760 793 end if 761 794 … … 921 954 if count(val) then 922 955 if ilk(retlist) = #proplist then 923 retlist.addProp(symbol(inputlist[n].getaprop(#name)), mConvertXMLPropList(me, val, convertValues, dontEscapeSpecialChars))924 else956 retlist.addProp(symbol(inputlist[n].getaprop(#name)), mConvertXMLPropList(me, val, convertValues, dontEscapeSpecialChars)) 957 else 925 958 retlist.add(mConvertXMLPropList(me, val, convertValues, dontEscapeSpecialChars)) 926 959 end if … … 943 976 944 977 -- unescape <>&'" 945 if dontEscapeSpecialChars <> 1 then val = mUnEscapeSpecialChars(me, val)978 if dontEscapeSpecialChars <> 1 then val = mUnEscapeSpecialChars(me, val) 946 979 947 980 #integer: … … 988 1021 989 1022 -- unescape <>&'" 990 if dontEscapeSpecialChars <> 1 then val = mUnEscapeSpecialChars(me, val)1023 if dontEscapeSpecialChars <> 1 then val = mUnEscapeSpecialChars(me, val) 991 1024 992 1025 … … 1000 1033 1001 1034 if ilk(retlist) = #proplist then 1002 retlist.addProp(symbol(inputlist[n].getaprop(#name)), val)1035 retlist.addProp(symbol(inputlist[n].getaprop(#name)), val) 1003 1036 else 1004 1037 retlist.add(val) … … 1022 1055 -- INPUT: <theText> ; string ; required => xml formatted string 1023 1056 -- RETURNS: property list 1024 -- EXAMPLE: plist = xscr(#PseudoXMLPS).mParseExcelXML(xscr(#FileIOFunktionen).mGetTextFromFile())1057 -- EXAMPLE: plist = new(script "PseudoXMLPS").mParseExcelXML(xscr(#FileIOFunktionen).mGetTextFromFile()) 1025 1058 ----------------------------------- 1026 1059 … … 1061 1094 1062 1095 else 1063 call(#mPut, mGetXScript(), "mParseExcelXML: Row "&n&" Cell "&m&" is not a property list")1096 put "mParseExcelXML: Row "&n&" Cell "&m&" is not a property list" 1064 1097 end if -- if ilk(thisCell) = #proplist then 1065 1098 … … 1067 1100 1068 1101 else 1069 call(#mPut, mGetXScript(), "mParseExcelXML: Row "&n&" is not a list")1102 put "mParseExcelXML: Row "&n&" is not a list" 1070 1103 end if -- if listP(currRow) then 1071 1104 … … 1073 1106 1074 1107 else 1075 call(#mPut, mGetXScript(), "mParseExcelXML: Table not found")1108 put "mParseExcelXML: Table not found" 1076 1109 end if -- if listP(xmlList) then 1077 1110 1078 1111 else 1079 call(#mPut, mGetXScript(), "mParseExcelXML: Worksheet not found")1112 put "mParseExcelXML: Worksheet not found" 1080 1113 end if -- if ilk(xmlList) = #proplist then 1081 1114 1082 1115 else 1083 call(#mPut, mGetXScript(), "mParseExcelXML: Workbook not found")1116 put "mParseExcelXML: Workbook not found" 1084 1117 end if -- if ilk(xmlList) = #proplist then 1085 1118 1086 1119 else 1087 call(#mPut, mGetXScript(), "mParseExcelXML: ROOT is not a property list")1120 put "mParseExcelXML: ROOT is not a property list" 1088 1121 end if --if ilk(xmlList) = #proplist then 1089 1122 1090 1123 else 1091 call(#mPut, mGetXScript(), "mParseExcelXML: Xml parser makelist() returned empty list")1124 put "mParseExcelXML: Xml parser makelist() returned empty list" 1092 1125 end if -- if count(xmlList) > 0 then 1093 1126 1094 1127 else 1095 call(#mPut, mGetXScript(), "mParseExcelXML: Xml parser makelist() failed")1128 put "mParseExcelXML: Xml parser makelist() failed" 1096 1129 end if -- if listP(xmlList) then 1097 1130 1098 1131 else 1099 call(#mPut, mGetXScript(), "mParseExcelXML: Xml parser error: "&xmlp.getError())1132 put "mParseExcelXML: Xml parser error: "&xmlp.getError() 1100 1133 end if -- if voidP(xmlp.getError()) then 1101 1134 … … 1113 1146 -- INPUT: <pfad> ; string ; full pathname to plist file. This is optional, if it is void or "" a file selection dialog is displayed 1114 1147 -- RETURNS: property list 1115 -- EXAMPLE: plist = xscr(#PseudoXMLPS).mReadPList()1148 -- EXAMPLE: plist = new(script "PseudoXMLPS").mReadPList() 1116 1149 ----------------------------------- 1117 1150 … … 1186 1219 1187 1220 on mGetListFromPListString me, str 1188 return mConvertKeyList(me, mGetListFromXMLString (me, str, 0))1221 return mConvertKeyList(me, mGetListFromXMLStringX(me, str, 0)) 1189 1222 end 1190 1223
Note: See TracChangeset
for help on using the changeset viewer.
