Farbflash projects: Imaging lingo table | 3-D scene list | Find all | Handler menu | Lingo message window
wiki:lingo/libraryScript/xmlParser
Last modified 3 years ago Last modified on 12/06/08 11:53:04

Back to parent page

Error: Macro AutoNav() failed
'Formatter' object has no attribute 'db'

Table of Contents

    Script: PseudoXMLPS


    PseudoXMLPS
    CREATED:
    2002
    DESCRIPTION:
    Pseudo XML by Alex da Franca c2003
    Convert a lingo list to a XML like string and back

    REQUIRES:
    only the functions mSaveList_2_XML() and mReadXML_2_List() require my system of library scripts
    in order to write and read text with fileio. All other functions have no dependencies
    Either get these scripts from my website, or replace the write/read stuff with your own fileIO handlers
    That is:
    • movie script "aleXtrasMovieScript"

    • parent script "commonMovieScript"

    • parent script "FileIOFunktionen"

    USAGE:




    PseudoXMLPS = new(script "PseudoXMLPS")
    -- Convert a list to an xml string:
    xmlString = PseudoXMLPS.mGetXMLStringFromList(["one", "two", 3])
    lingolist = PseudoXMLPS.mGetListFromXMLString(xmlString)
















    EXAMPLE for <dontReplaceGT = 1> (dontReplaceGT means don't replace "greater than" btw...):

    myList = string with invalid chars like <> and & and ' and " & QUOTE
    myList#stringWithInvalidChars = "<![CDATA& myList[?]>"
    xmlString = PseudoXMLPS.mGetXMLStringFromList(myList, "myList", 1, 1)
    ...
    myList = PseudoXMLPS.mGetListFromXMLString(xmlString)
    repeat with n = countmyList) down to 1
    thisValue = myList[n]
    if ilk(thisValue) = #string then
    if thisValue starts "<![CDATA[" then
    delete char 1 to 9 of thisValue
    delete char length(thisValue) - 2 to length(thisValue) of thisValue
    myList[n] = thisValue
    end if
    end if
    end repeat
    please note, that the above example is ONLY needed, if you use dontReplaceGT = 1 !!
    HISTORY:

    alex am Freitag 21.April.2006 16:31:57
    fixed a bug in "mBuildXMLString" many thanks to Olaf Schliesing for pointing this out

    alex am 28.11.06 um 16:41:00
    finally added a tag property, when writing xml, so the ilk of the object gets stored
    so, when reading back the xml file, we do not convert a node by accident to a value
    when a string evaluates to a value "by accident"
    Scriptmarker: changes alex (04.04.2007 at 10:22 Uhr) Scriptmarker
    added escaping of:
    & -> &amp;
    ' -> &apos;
    " -> &quot;
    and vice versa. Until now I only escaped < and >, but ampersand, apostrophe and quote must also be escaped for proper xml
    I als added "support" for the CData tag, which allows you to escape the whole contents of a node.
    support is only done through ignoring esaping the special characters, wehn BUILDING the xml string.
    So the user can decide on his own, which nodes s/he wants to be masked inside a CData section
    (otherwise I'd have to mask EVERY string and try to unmask EVERY node. Now the user is on his own)
    TODO:
    -

    Syntax:
    mGetXMLStringFromList(me, listref, docName, strict, dontReplaceGT, withParams)


    CREATED:
    06.03.2008
    ACTION:
    Convert lingo list (also nested lists) to XML stylish string
    INPUT:

    <listref> format: property list or linear list
    <docName> format: #string; optional. if omitted "Untitled" is used for the XML document name
    <strict> => boolean; avoid spaces in tag names
    <dontReplaceGT> => boolean; dont replace < and >
    <withParams> => boolean; write attribute in tag for the lingo ilk => bigger xml files and unfortunately it is slower to parse
    (I thought avoiding value() would help, but in this case the additional text parsing of the attributes tag slows down)
    RETURNS:
    string
    EXAMPLE:
    saveString = mGetXMLStringFromList(me, lingo_list, "documentName")


    ms = the milliseconds
    Back to top
    Syntax:
    mGetListFromXMLStringlingo(me, str, convertValues, withParams)


    CREATED:
    06.03.2008
    ACTION:
    Description
    INPUT:

    <str> format: #string; split a string using <> and </> tags into lingo list
    <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)
    <withParams> : #boolean : parse parameters too. new, not very well tested
    RETURNS:
    property list
    EXAMPLE:
    lingo_list = mGetListFromXMLStringlingo(me, saveString)
    CHANGES:
    implemented parameter parsing
    Back to top
    Syntax:
    mGetListFromXMLString(me, str, convertValues, withParams)


    CREATED:
    06.03.2008
    ACTION:
    Convert xml string to lingo list using the xmlparser xtra, if possible
    MUCH FASTER than the above: Use the XML xtra to parse the string
    BUT it must be a valid xml string, the above is slower but allows more malformed xml
    INPUT:

    <str> format: #string; split a string using <> and </> tags into lingo list
    <convertValues> #integer
    -- -- 0 => don't convert (fast, all values are strings)
    -- -- 1 => convert only integer() and float() (slower)
    -- -- 2 => try to convert all data with value(), even parse for colors in hexstring format (slow)
    RETURNS:
    property list
    EXAMPLE:
    lingo_list = mGetListFromXMLString(me, saveString)
    CHANGES:
    resorts to the slower lingo function on xml parser error. So this handler can always be used.
    Back to top
    Handler: mReadXML_2_List
    Syntax:
    mReadXML_2_List(me, thePath)


    CREATED:
    06.03.2008
    ACTION:
    read external xml file to lingo list
    INPUT:
    <thePath> : string ; optional pathname. if no pathname or "", then a file save dialog is shown
    RETURNS:
    property list
    Back to top
    Handler: mSaveList_2_XML
    Syntax:
    mSaveList_2_XML(me, theList, thePath)


    CREATED:
    06.03.2008
    ACTION:
    write liongo list to external xml file
    INPUT:

    <theList> : linear or property list
    <thePath> : string ; optional pathname. if no pathname or "", then a file selection dialog is shown
    RETURNS:
    full pathname of newly created file, if successful, otherwise 0
    Back to top
    Handler: mParseExcelXML
    Syntax:
    mParseExcelXML(me, theText)


    ACTION:
    Read and convert an excel xml file into a lingo property list
    INPUT:
    <theText> ; string ; required => xml formatted string
    RETURNS:
    property list
    EXAMPLE:
    plist = new(script "PseudoXMLPS").mParseExcelXML(xscr(#FileIOFunktionen).mGetTextFromFile())
    Back to top
    Handler: mReadPList
    Syntax:
    mReadPList(me, pfad)


    ACTION:
    Read and convrt an apple style plist into a lingo style property list from file
    INPUT:
    <pfad> ; string ; full pathname to plist file. This is optional, if it is void or "" a file selection dialog is displayed
    RETURNS:
    property list
    EXAMPLE:
    plist = new(script "PseudoXMLPS").mReadPList()
    Back to top