Farbflash projects: Imaging lingo table | 3-D scene list | Find all | Handler menu | Lingo message window

Ignore:
Timestamp:
04/06/08 11:11:43 (4 years ago)
Author:
alex
Message:

now with version checking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lingosource/castlib2/PseudoXMLPS.ls

    r150 r163  
     1-- PseudoXMLPS 
     2----------------------------------- 
     3-- CREATED: 
     4-- 06.03.2008 
     5-- 
     6-- DESCRIPTION: 
    17-- Pseudo XML by Alex da Franca ©2003 
    28-- Convert a lingo list to a XML like string and back 
    39 
    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: 
    2815-- myList = [#stringWithInvalidChars:"A string with invalid chars like <> and & and ' and " & QUOTE] 
    2916-- myList[#stringWithInvalidChars] = "<![CDATA[" & myList[#stringWithInvalidChars] & "]]>" 
     
    4128--   end if 
    4229-- 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--                                   & -> &amp; 
     44--                                   ' -> &apos; 
     45--                                   " -> &quot; 
     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 
    4360 
    4461 
     
    112129-- xxxxxxxxxxxxxxxxxx Convert lingo list (also nested lists) to XML stylish string 
    113130 
    114 -- Parameters: 
     131on 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:  
    115136-- <listref> format: property list or linear list 
    116137-- <docName> format: #string; optional. if omitted "Untitled" is used for the XML document name 
    117 -- strict        => boolean; avoid spaces in tag names 
    118 -- 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 parse 
     138  --              <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 
    120141----------------------------- (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   
    126146  --  ms = the milliseconds 
    127147  if voidP(strict) then strict = 0 
     
    152172-- xxxxxxxxxxxxxxxxxx Convert XML stylish string to lingo list 
    153173 
    154 -- Parameters: 
     174 
     175on mGetListFromXMLString me, str, convertValues, withParams 
     176  ----------------------------------- 
     177  -- CREATED: 06.03.2008 
     178  -- ACTION: Description 
     179  -- INPUT: 
    155180-- <str> format: #string; split a string using <> and </> tags into lingo list 
    156181-- <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  ----------------------------------- 
    162187   
    163188  ms = the milliseconds 
     
    193218 
    194219-- 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 
     222property pXmlxtraversion 
     223 
     224on 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:  
    199231-- <str> format: #string; split a string using <> and </> tags into lingo list 
    200232-- <convertValues> #integer 
     
    202234-- -- -- 1 => convert only integer() and float() (slower) 
    203235-- -- -- 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  ----------------------------------- 
    211240   
    212241  if ilk(str) <> #string then str = string(str) 
     
    289318   
    290319end 
     320 
     321-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
     322on _______________READ_WRITE_EXTERNAL_FILES 
     323end 
     324-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
     325 
     326on 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 [:] 
     337end 
     338 
     339-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
     340 
     341on 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) 
     354end 
     355 
    291356 
    292357-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
     
    9401005         
    9411006        if ilk(retlist) = #proplist then 
    942           retlist.addProp(symbol(inputlist[n].getaprop(#name)), val) 
     1007        retlist.addProp(symbol(inputlist[n].getaprop(#name)), val) 
    9431008        else 
    9441009          retlist.add(val) 
     
    9941059                         
    9951060                      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") 
    9971062                      end if -- if ilk(thisCell) = #proplist then 
    9981063                       
     
    10001065                     
    10011066                  else 
    1002                     call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Row "&n&" is not a list") 
     1067                    call(#mPut, mGetXScript(), "mParseExcelXML: Row "&n&" is not a list") 
    10031068                  end if -- if listP(currRow) then 
    10041069                   
     
    10061071                 
    10071072              else 
    1008                 call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Table not found") 
     1073                call(#mPut, mGetXScript(), "mParseExcelXML: Table not found") 
    10091074              end if -- if listP(xmlList) then 
    10101075               
    10111076            else 
    1012               call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Worksheet not found") 
     1077              call(#mPut, mGetXScript(), "mParseExcelXML: Worksheet not found") 
    10131078            end if -- if ilk(xmlList) = #proplist then 
    10141079             
    10151080          else 
    1016             call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Workbook not found") 
     1081            call(#mPut, mGetXScript(), "mParseExcelXML: Workbook not found") 
    10171082          end if -- if ilk(xmlList) = #proplist then 
    10181083           
    10191084        else 
    1020           call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: ROOT is not a property list") 
     1085          call(#mPut, mGetXScript(), "mParseExcelXML: ROOT is not a property list") 
    10211086        end if --if ilk(xmlList) = #proplist then 
    10221087         
    10231088      else 
    1024         call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Xml parser makelist() returned empty list") 
     1089        call(#mPut, mGetXScript(), "mParseExcelXML: Xml parser makelist() returned empty list") 
    10251090      end if -- if count(xmlList) > 0 then 
    10261091       
    10271092    else 
    1028       call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Xml parser makelist() failed") 
     1093      call(#mPut, mGetXScript(), "mParseExcelXML: Xml parser makelist() failed") 
    10291094    end if -- if listP(xmlList) then 
    10301095     
    10311096  else 
    1032     call(#mPut, [mGetXScript(#commonmoviescript)], "mParseExcelXML: Xml parser error: "&xmlp.getError()) 
     1097    call(#mPut, mGetXScript(), "mParseExcelXML: Xml parser error: "&xmlp.getError()) 
    10331098  end if -- if voidP(xmlp.getError()) then 
    10341099   
Note: See TracChangeset for help on using the changeset viewer.