XML encoding oddities

Trevor DeVore lists at mangomultimedia.com
Mon Nov 10 11:57:36 EST 2008


On Nov 10, 2008, at 11:21 AM, Mark Smith wrote:

> Thanks Trevor! (Also Ken). That seems to work very well.
>
> The particular problem I was trying to solve was how to serialize  
> arrays with arbitrary keys and contents, such that they can be  
> shared across networks and platforms. I think I've found a solution  
> for my purposes, (though it won't be reliable with binary data), and  
> it involves building the xml without the xml library, and then using  
> the library to unserialize - though it fails if there is any "<? 
> xml..." header at all!

Mark,

For what it's worth I've been using the attached SerializeArray/ 
UnserializeArray handlers with relatively small arrays for a while now  
and they seem to be working well enough for storing them in a database.

Regards,

-- 
Trevor DeVore
Blue Mango Learning Systems
ScreenSteps: http://www.screensteps.com
Developer Resources: http://revolution.bluemangolearning.com



function SerializeArray pArray
    repeat for each key theKey in pArray
       if the keys of pArray[theKey] is not empty then
          put urlencode(theKey) & ":" & "___array___:" &  
urlencode(SerializeArray(pArray[theKey])) & cr after theData
       else
          put urlencode(theKey) & ":" &  
urlencode(base64encode(pArray[theKey])) & cr after theData
       end if
    end repeat
    delete the last char of theData
    return theData
end SerializeArray

-- Returns array
-- Support Rev 3.0 multi-dimensional arrays
function UnserializeArray pSerializedArray
    set the itemdelimiter to ":"
    repeat for each line theLine in pSerializedArray
       if item 2 of theLine begins with "___array___" then
          put urldecode(item 1 of theLine) into theKey
          put UnserializeArray(urldecode(item 3 of theLine)) into  
theArray[theKey]
       else
          put urldecode(item 1 of theLine) into theKey
          put base64decode(urldecode(item 2 to -1 of theLine)) into  
theArray[theKey]
       end if
    end repeat
    return theArray
end UnserializeArray



More information about the use-livecode mailing list